| 1 | |
package org.apache.maven.project; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
import org.apache.maven.artifact.Artifact; |
| 23 | |
import org.apache.maven.artifact.ArtifactStatus; |
| 24 | |
import org.apache.maven.artifact.ArtifactUtils; |
| 25 | |
import org.apache.maven.artifact.InvalidRepositoryException; |
| 26 | |
import org.apache.maven.artifact.factory.ArtifactFactory; |
| 27 | |
import org.apache.maven.artifact.manager.WagonManager; |
| 28 | |
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; |
| 29 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
| 30 | |
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; |
| 31 | |
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; |
| 32 | |
import org.apache.maven.artifact.resolver.ArtifactNotFoundException; |
| 33 | |
import org.apache.maven.artifact.resolver.ArtifactResolutionException; |
| 34 | |
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; |
| 35 | |
import org.apache.maven.artifact.resolver.ArtifactResolver; |
| 36 | |
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; |
| 37 | |
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; |
| 38 | |
import org.apache.maven.artifact.versioning.ManagedVersionMap; |
| 39 | |
import org.apache.maven.artifact.versioning.VersionRange; |
| 40 | |
import org.apache.maven.model.Build; |
| 41 | |
import org.apache.maven.model.Dependency; |
| 42 | |
import org.apache.maven.model.DependencyManagement; |
| 43 | |
import org.apache.maven.model.DistributionManagement; |
| 44 | |
import org.apache.maven.model.Exclusion; |
| 45 | |
import org.apache.maven.model.Extension; |
| 46 | |
import org.apache.maven.model.Model; |
| 47 | |
import org.apache.maven.model.Parent; |
| 48 | |
import org.apache.maven.model.Plugin; |
| 49 | |
import org.apache.maven.model.Profile; |
| 50 | |
import org.apache.maven.model.ReportPlugin; |
| 51 | |
import org.apache.maven.model.Repository; |
| 52 | |
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; |
| 53 | |
import org.apache.maven.profiles.DefaultProfileManager; |
| 54 | |
import org.apache.maven.profiles.MavenProfilesBuilder; |
| 55 | |
import org.apache.maven.profiles.ProfileManager; |
| 56 | |
import org.apache.maven.profiles.ProfilesConversionUtils; |
| 57 | |
import org.apache.maven.profiles.ProfilesRoot; |
| 58 | |
import org.apache.maven.profiles.activation.ProfileActivationException; |
| 59 | |
import org.apache.maven.project.artifact.InvalidDependencyVersionException; |
| 60 | |
import org.apache.maven.project.inheritance.ModelInheritanceAssembler; |
| 61 | |
import org.apache.maven.project.injection.ModelDefaultsInjector; |
| 62 | |
import org.apache.maven.project.injection.ProfileInjector; |
| 63 | |
import org.apache.maven.project.interpolation.ModelInterpolationException; |
| 64 | |
import org.apache.maven.project.interpolation.ModelInterpolator; |
| 65 | |
import org.apache.maven.project.path.PathTranslator; |
| 66 | |
import org.apache.maven.project.validation.ModelValidationResult; |
| 67 | |
import org.apache.maven.project.validation.ModelValidator; |
| 68 | |
import org.apache.maven.wagon.events.TransferListener; |
| 69 | |
import org.codehaus.plexus.PlexusConstants; |
| 70 | |
import org.codehaus.plexus.PlexusContainer; |
| 71 | |
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; |
| 72 | |
import org.codehaus.plexus.context.Context; |
| 73 | |
import org.codehaus.plexus.context.ContextException; |
| 74 | |
import org.codehaus.plexus.logging.AbstractLogEnabled; |
| 75 | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; |
| 76 | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; |
| 77 | |
import org.codehaus.plexus.util.IOUtil; |
| 78 | |
import org.codehaus.plexus.util.ReaderFactory; |
| 79 | |
import org.codehaus.plexus.util.StringUtils; |
| 80 | |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
| 81 | |
|
| 82 | |
import java.io.File; |
| 83 | |
import java.io.FileNotFoundException; |
| 84 | |
import java.io.IOException; |
| 85 | |
import java.io.Reader; |
| 86 | |
import java.io.StringReader; |
| 87 | |
import java.net.URL; |
| 88 | |
import java.util.ArrayList; |
| 89 | |
import java.util.Collections; |
| 90 | |
import java.util.Date; |
| 91 | |
import java.util.HashMap; |
| 92 | |
import java.util.Iterator; |
| 93 | |
import java.util.LinkedHashSet; |
| 94 | |
import java.util.LinkedList; |
| 95 | |
import java.util.List; |
| 96 | |
import java.util.Map; |
| 97 | |
import java.util.Properties; |
| 98 | |
import java.util.Set; |
| 99 | |
import java.util.TreeMap; |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | 0 | public class DefaultMavenProjectBuilder |
| 139 | |
extends AbstractLogEnabled |
| 140 | |
implements MavenProjectBuilder, Initializable, Contextualizable |
| 141 | |
{ |
| 142 | |
|
| 143 | |
private PlexusContainer container; |
| 144 | |
|
| 145 | |
protected MavenProfilesBuilder profilesBuilder; |
| 146 | |
|
| 147 | |
protected ArtifactResolver artifactResolver; |
| 148 | |
|
| 149 | |
protected ArtifactMetadataSource artifactMetadataSource; |
| 150 | |
|
| 151 | |
private ArtifactFactory artifactFactory; |
| 152 | |
|
| 153 | |
private ModelInheritanceAssembler modelInheritanceAssembler; |
| 154 | |
|
| 155 | |
private ProfileInjector profileInjector; |
| 156 | |
|
| 157 | |
private ModelValidator validator; |
| 158 | |
|
| 159 | 0 | private Map rawProjectCache = new HashMap(); |
| 160 | |
|
| 161 | 0 | private Map processedProjectCache = new HashMap(); |
| 162 | |
|
| 163 | |
|
| 164 | |
private MavenXpp3Reader modelReader; |
| 165 | |
|
| 166 | |
private PathTranslator pathTranslator; |
| 167 | |
|
| 168 | |
private ModelDefaultsInjector modelDefaultsInjector; |
| 169 | |
|
| 170 | |
private ModelInterpolator modelInterpolator; |
| 171 | |
|
| 172 | |
private ArtifactRepositoryFactory artifactRepositoryFactory; |
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
private WagonManager wagonManager; |
| 181 | |
|
| 182 | |
public static final String MAVEN_MODEL_VERSION = "4.0.0"; |
| 183 | |
|
| 184 | |
public void initialize() |
| 185 | |
{ |
| 186 | 0 | modelReader = new MavenXpp3Reader(); |
| 187 | 0 | } |
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
public MavenProject build( File pom, |
| 194 | |
ProjectBuilderConfiguration config ) |
| 195 | |
throws ProjectBuildingException |
| 196 | |
{ |
| 197 | 0 | return buildFromSourceFileInternal( pom, config, true ); |
| 198 | |
} |
| 199 | |
|
| 200 | |
public MavenProject build( File pom, |
| 201 | |
ProjectBuilderConfiguration config, |
| 202 | |
boolean checkDistributionManagementStatus ) |
| 203 | |
throws ProjectBuildingException |
| 204 | |
{ |
| 205 | 0 | return buildFromSourceFileInternal( pom, config, checkDistributionManagementStatus ); |
| 206 | |
} |
| 207 | |
|
| 208 | |
public MavenProject build( File projectDescriptor, |
| 209 | |
ArtifactRepository localRepository, |
| 210 | |
ProfileManager profileManager ) |
| 211 | |
throws ProjectBuildingException |
| 212 | |
{ |
| 213 | 0 | ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ).setGlobalProfileManager( profileManager ); |
| 214 | 0 | return buildFromSourceFileInternal( projectDescriptor, config, true ); |
| 215 | |
} |
| 216 | |
|
| 217 | |
public MavenProject build( File projectDescriptor, |
| 218 | |
ArtifactRepository localRepository, |
| 219 | |
ProfileManager profileManager, |
| 220 | |
boolean checkDistributionManagementStatus ) |
| 221 | |
throws ProjectBuildingException |
| 222 | |
{ |
| 223 | 0 | ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ).setGlobalProfileManager( profileManager ); |
| 224 | 0 | return buildFromSourceFileInternal( projectDescriptor, config, checkDistributionManagementStatus ); |
| 225 | |
} |
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
public MavenProject buildFromRepository( Artifact artifact, |
| 234 | |
List remoteArtifactRepositories, |
| 235 | |
ArtifactRepository localRepository, |
| 236 | |
boolean allowStubModel ) |
| 237 | |
throws ProjectBuildingException |
| 238 | |
{ |
| 239 | 0 | String cacheKey = createCacheKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); |
| 240 | |
|
| 241 | 0 | MavenProject project = (MavenProject) processedProjectCache.get( cacheKey ); |
| 242 | |
|
| 243 | 0 | if ( project != null ) |
| 244 | |
{ |
| 245 | 0 | return project; |
| 246 | |
} |
| 247 | |
|
| 248 | 0 | Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository, allowStubModel ); |
| 249 | |
|
| 250 | 0 | ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ); |
| 251 | |
|
| 252 | 0 | return buildInternal( "Artifact [" + artifact + "]", model, config, remoteArtifactRepositories, |
| 253 | |
null, false ); |
| 254 | |
} |
| 255 | |
|
| 256 | |
public MavenProject buildFromRepository( Artifact artifact, |
| 257 | |
List remoteArtifactRepositories, |
| 258 | |
ArtifactRepository localRepository ) |
| 259 | |
throws ProjectBuildingException |
| 260 | |
{ |
| 261 | 0 | return buildFromRepository( artifact, remoteArtifactRepositories, localRepository, true ); |
| 262 | |
} |
| 263 | |
|
| 264 | |
|
| 265 | |
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository ) |
| 266 | |
throws ProjectBuildingException |
| 267 | |
{ |
| 268 | |
|
| 269 | 0 | ProfileManager profileManager = new DefaultProfileManager( container ); |
| 270 | |
|
| 271 | 0 | return buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ) |
| 272 | |
.setGlobalProfileManager( profileManager ) ); |
| 273 | |
} |
| 274 | |
|
| 275 | |
public MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, |
| 276 | |
ProfileManager profileManager ) |
| 277 | |
throws ProjectBuildingException |
| 278 | |
{ |
| 279 | 0 | return buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ) |
| 280 | |
.setGlobalProfileManager( profileManager ) ); |
| 281 | |
} |
| 282 | |
|
| 283 | |
public MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration config ) |
| 284 | |
throws ProjectBuildingException |
| 285 | |
{ |
| 286 | 0 | Model superModel = getSuperModel(); |
| 287 | |
|
| 288 | 0 | superModel.setGroupId( STANDALONE_SUPERPOM_GROUPID ); |
| 289 | |
|
| 290 | 0 | superModel.setArtifactId( STANDALONE_SUPERPOM_ARTIFACTID ); |
| 291 | |
|
| 292 | 0 | superModel.setVersion( STANDALONE_SUPERPOM_VERSION ); |
| 293 | |
|
| 294 | |
|
| 295 | |
List activeProfiles; |
| 296 | |
|
| 297 | 0 | ProfileManager profileManager = config.getGlobalProfileManager(); |
| 298 | |
|
| 299 | 0 | if ( profileManager == null ) |
| 300 | |
{ |
| 301 | 0 | profileManager = new DefaultProfileManager( container ); |
| 302 | |
} |
| 303 | |
|
| 304 | 0 | profileManager.addProfiles( superModel.getProfiles() ); |
| 305 | |
|
| 306 | 0 | String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID ); |
| 307 | |
|
| 308 | 0 | activeProfiles = injectActiveProfiles( profileManager, superModel ); |
| 309 | |
|
| 310 | 0 | MavenProject project = new MavenProject( superModel ); |
| 311 | |
|
| 312 | 0 | project.setManagedVersionMap( |
| 313 | |
createManagedVersionMap( projectId, superModel.getDependencyManagement(), null ) ); |
| 314 | |
|
| 315 | 0 | project.setActiveProfiles( activeProfiles ); |
| 316 | |
|
| 317 | 0 | project.setOriginalModel( superModel ); |
| 318 | |
|
| 319 | |
try |
| 320 | |
{ |
| 321 | 0 | project = processProjectLogic( "<Super-POM>", project, config, null, null, true, true ); |
| 322 | |
|
| 323 | 0 | project.setExecutionRoot( true ); |
| 324 | |
|
| 325 | 0 | return project; |
| 326 | |
} |
| 327 | 0 | catch ( ModelInterpolationException e ) |
| 328 | |
{ |
| 329 | 0 | throw new ProjectBuildingException( projectId, e.getMessage(), e ); |
| 330 | |
} |
| 331 | 0 | catch ( InvalidRepositoryException e ) |
| 332 | |
{ |
| 333 | 0 | throw new ProjectBuildingException( projectId, e.getMessage(), e ); |
| 334 | |
} |
| 335 | |
} |
| 336 | |
|
| 337 | |
public MavenProject buildWithDependencies( File projectDescriptor, |
| 338 | |
ArtifactRepository localRepository, |
| 339 | |
ProfileManager profileManager ) |
| 340 | |
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException |
| 341 | |
{ |
| 342 | 0 | return buildWithDependencies( projectDescriptor, localRepository, profileManager, null ); |
| 343 | |
} |
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
public MavenProject buildWithDependencies( File projectDescriptor, |
| 349 | |
ArtifactRepository localRepository, |
| 350 | |
ProfileManager profileManager, |
| 351 | |
TransferListener transferListener ) |
| 352 | |
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException |
| 353 | |
{ |
| 354 | 0 | MavenProject project = build( projectDescriptor, localRepository, profileManager, false ); |
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | 0 | Artifact projectArtifact = project.getArtifact(); |
| 370 | |
|
| 371 | 0 | String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId() ); |
| 372 | |
|
| 373 | |
|
| 374 | 0 | Map managedVersions = project.getManagedVersionMap(); |
| 375 | |
|
| 376 | 0 | ensureMetadataSourceIsInitialized(); |
| 377 | |
|
| 378 | |
try |
| 379 | |
{ |
| 380 | 0 | project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) ); |
| 381 | |
} |
| 382 | 0 | catch ( InvalidDependencyVersionException e ) |
| 383 | |
{ |
| 384 | 0 | throw new ProjectBuildingException( projectId, |
| 385 | |
"Unable to build project due to an invalid dependency version: " + |
| 386 | |
e.getMessage(), e ); |
| 387 | 0 | } |
| 388 | |
|
| 389 | 0 | if ( transferListener != null ) |
| 390 | |
{ |
| 391 | 0 | wagonManager.setDownloadMonitor( transferListener ); |
| 392 | |
} |
| 393 | |
|
| 394 | 0 | ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(), |
| 395 | |
projectArtifact, managedVersions, |
| 396 | |
localRepository, |
| 397 | |
project.getRemoteArtifactRepositories(), |
| 398 | |
artifactMetadataSource ); |
| 399 | |
|
| 400 | 0 | project.setArtifacts( result.getArtifacts() ); |
| 401 | |
|
| 402 | 0 | return project; |
| 403 | |
} |
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
private void ensureMetadataSourceIsInitialized() |
| 410 | |
throws ProjectBuildingException |
| 411 | |
{ |
| 412 | 0 | if ( artifactMetadataSource == null ) |
| 413 | |
{ |
| 414 | |
try |
| 415 | |
{ |
| 416 | 0 | artifactMetadataSource = (ArtifactMetadataSource) container.lookup( ArtifactMetadataSource.ROLE ); |
| 417 | |
} |
| 418 | 0 | catch ( ComponentLookupException e ) |
| 419 | |
{ |
| 420 | 0 | throw new ProjectBuildingException( "all", "Cannot lookup metadata source for building the project.", |
| 421 | |
e ); |
| 422 | 0 | } |
| 423 | |
} |
| 424 | 0 | } |
| 425 | |
|
| 426 | |
private Map createManagedVersionMap( String projectId, |
| 427 | |
DependencyManagement dependencyManagement, |
| 428 | |
MavenProject parent ) |
| 429 | |
throws ProjectBuildingException |
| 430 | |
{ |
| 431 | 0 | Map map = null; |
| 432 | |
List deps; |
| 433 | 0 | if ( ( dependencyManagement != null ) && ( ( deps = dependencyManagement.getDependencies() ) != null ) && |
| 434 | |
( deps.size() > 0 ) ) |
| 435 | |
{ |
| 436 | 0 | map = new ManagedVersionMap( map ); |
| 437 | |
|
| 438 | 0 | if ( getLogger().isDebugEnabled() ) |
| 439 | |
{ |
| 440 | 0 | getLogger().debug( "Adding managed dependencies for " + projectId ); |
| 441 | |
} |
| 442 | |
|
| 443 | 0 | for ( Iterator i = dependencyManagement.getDependencies().iterator(); i.hasNext(); ) |
| 444 | |
{ |
| 445 | 0 | Dependency d = (Dependency) i.next(); |
| 446 | |
|
| 447 | |
try |
| 448 | |
{ |
| 449 | 0 | VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() ); |
| 450 | |
|
| 451 | 0 | Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), |
| 452 | |
versionRange, d.getType(), |
| 453 | |
d.getClassifier(), d.getScope(), |
| 454 | |
d.isOptional() ); |
| 455 | 0 | if ( getLogger().isDebugEnabled() ) |
| 456 | |
{ |
| 457 | 0 | getLogger().debug( " " + artifact ); |
| 458 | |
} |
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | 0 | if ( ( null != d.getExclusions() ) && !d.getExclusions().isEmpty() ) |
| 464 | |
{ |
| 465 | 0 | List exclusions = new ArrayList(); |
| 466 | |
|
| 467 | 0 | Iterator exclItr = d.getExclusions().iterator(); |
| 468 | |
|
| 469 | 0 | while ( exclItr.hasNext() ) |
| 470 | |
{ |
| 471 | 0 | Exclusion e = (Exclusion) exclItr.next(); |
| 472 | 0 | exclusions.add( e.getGroupId() + ":" + e.getArtifactId() ); |
| 473 | 0 | } |
| 474 | 0 | ExcludesArtifactFilter eaf = new ExcludesArtifactFilter( exclusions ); |
| 475 | 0 | artifact.setDependencyFilter( eaf ); |
| 476 | 0 | } |
| 477 | |
else |
| 478 | |
{ |
| 479 | 0 | artifact.setDependencyFilter( null ); |
| 480 | |
} |
| 481 | 0 | map.put( d.getManagementKey(), artifact ); |
| 482 | |
} |
| 483 | 0 | catch ( InvalidVersionSpecificationException e ) |
| 484 | |
{ |
| 485 | 0 | throw new ProjectBuildingException( projectId, "Unable to parse version '" + d.getVersion() + |
| 486 | |
"' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e ); |
| 487 | 0 | } |
| 488 | 0 | } |
| 489 | |
} |
| 490 | 0 | else if ( map == null ) |
| 491 | |
{ |
| 492 | 0 | map = Collections.EMPTY_MAP; |
| 493 | |
} |
| 494 | |
|
| 495 | 0 | return map; |
| 496 | |
} |
| 497 | |
|
| 498 | |
private MavenProject buildFromSourceFileInternal( File projectDescriptor, |
| 499 | |
ProjectBuilderConfiguration config, |
| 500 | |
boolean checkDistributionManagementStatus ) |
| 501 | |
throws ProjectBuildingException |
| 502 | |
{ |
| 503 | 0 | Model model = readModel( "unknown", projectDescriptor, true ); |
| 504 | |
|
| 505 | 0 | MavenProject project = buildInternal( projectDescriptor.getAbsolutePath(), model, config, |
| 506 | |
buildArtifactRepositories( getSuperModel() ), projectDescriptor, |
| 507 | |
true ); |
| 508 | |
|
| 509 | 0 | if ( checkDistributionManagementStatus ) |
| 510 | |
{ |
| 511 | 0 | if ( ( project.getDistributionManagement() != null ) && |
| 512 | |
( project.getDistributionManagement().getStatus() != null ) ) |
| 513 | |
{ |
| 514 | 0 | String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId() ); |
| 515 | |
|
| 516 | 0 | throw new ProjectBuildingException( projectId, |
| 517 | |
"Invalid project file: distribution status must not be specified for a project outside of the repository" ); |
| 518 | |
} |
| 519 | |
} |
| 520 | |
|
| 521 | 0 | return project; |
| 522 | |
} |
| 523 | |
|
| 524 | |
private Model findModelFromRepository( Artifact artifact, |
| 525 | |
List remoteArtifactRepositories, |
| 526 | |
ArtifactRepository localRepository, |
| 527 | |
boolean allowStubModel ) |
| 528 | |
throws ProjectBuildingException |
| 529 | |
{ |
| 530 | 0 | String projectId = safeVersionlessKey( artifact.getGroupId(), artifact.getArtifactId() ); |
| 531 | |
|
| 532 | 0 | normalizeToArtifactRepositories( remoteArtifactRepositories, projectId ); |
| 533 | |
|
| 534 | |
Artifact projectArtifact; |
| 535 | |
|
| 536 | |
|
| 537 | 0 | if ( "pom".equals( artifact.getType() ) ) |
| 538 | |
{ |
| 539 | 0 | projectArtifact = artifact; |
| 540 | |
} |
| 541 | |
else |
| 542 | |
{ |
| 543 | 0 | getLogger().warn( "Attempting to build MavenProject instance for Artifact (" + artifact.getGroupId() + ":" |
| 544 | |
+ artifact.getArtifactId() + ":" + artifact.getVersion() + ") of type: " |
| 545 | |
+ artifact.getType() + "; constructing POM artifact instead." ); |
| 546 | |
|
| 547 | 0 | projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), |
| 548 | |
artifact.getVersion(), artifact.getScope() ); |
| 549 | |
} |
| 550 | |
|
| 551 | |
Model model; |
| 552 | |
|
| 553 | |
try |
| 554 | |
{ |
| 555 | 0 | artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository ); |
| 556 | |
|
| 557 | 0 | File file = projectArtifact.getFile(); |
| 558 | |
|
| 559 | 0 | model = readModel( projectId, file, false ); |
| 560 | |
|
| 561 | 0 | String downloadUrl = null; |
| 562 | |
|
| 563 | 0 | ArtifactStatus status = ArtifactStatus.NONE; |
| 564 | |
|
| 565 | 0 | DistributionManagement distributionManagement = model.getDistributionManagement(); |
| 566 | |
|
| 567 | 0 | if ( distributionManagement != null ) |
| 568 | |
{ |
| 569 | 0 | downloadUrl = distributionManagement.getDownloadUrl(); |
| 570 | |
|
| 571 | 0 | status = ArtifactStatus.valueOf( distributionManagement.getStatus() ); |
| 572 | |
} |
| 573 | |
|
| 574 | 0 | checkStatusAndUpdate( projectArtifact, status, file, remoteArtifactRepositories, localRepository ); |
| 575 | |
|
| 576 | |
|
| 577 | |
|
| 578 | 0 | if ( downloadUrl != null ) |
| 579 | |
{ |
| 580 | 0 | projectArtifact.setDownloadUrl( downloadUrl ); |
| 581 | |
} |
| 582 | |
else |
| 583 | |
{ |
| 584 | 0 | projectArtifact.setDownloadUrl( model.getUrl() ); |
| 585 | |
} |
| 586 | |
} |
| 587 | 0 | catch ( ArtifactResolutionException e ) |
| 588 | |
{ |
| 589 | 0 | throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId + |
| 590 | |
"' from the repository: " + e.getMessage(), e ); |
| 591 | |
} |
| 592 | 0 | catch ( ArtifactNotFoundException e ) |
| 593 | |
{ |
| 594 | 0 | if ( allowStubModel ) |
| 595 | |
{ |
| 596 | 0 | getLogger().debug( "Artifact not found - using stub model: " + e.getMessage() ); |
| 597 | |
|
| 598 | 0 | model = createStubModel( projectArtifact ); |
| 599 | |
} |
| 600 | |
else |
| 601 | |
{ |
| 602 | 0 | throw new ProjectBuildingException( projectId, "POM '" + projectId + "' not found in repository: " + |
| 603 | |
e.getMessage(), e ); |
| 604 | |
} |
| 605 | 0 | } |
| 606 | |
|
| 607 | 0 | return model; |
| 608 | |
} |
| 609 | |
|
| 610 | |
private List normalizeToArtifactRepositories( List remoteArtifactRepositories, |
| 611 | |
String projectId ) |
| 612 | |
throws ProjectBuildingException |
| 613 | |
{ |
| 614 | 0 | List normalized = new ArrayList( remoteArtifactRepositories.size() ); |
| 615 | |
|
| 616 | 0 | boolean normalizationNeeded = false; |
| 617 | 0 | for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); ) |
| 618 | |
{ |
| 619 | 0 | Object item = it.next(); |
| 620 | |
|
| 621 | 0 | if ( item instanceof ArtifactRepository ) |
| 622 | |
{ |
| 623 | 0 | normalized.add( item ); |
| 624 | |
} |
| 625 | 0 | else if ( item instanceof Repository ) |
| 626 | |
{ |
| 627 | 0 | Repository repo = (Repository) item; |
| 628 | |
try |
| 629 | |
{ |
| 630 | 0 | item = ProjectUtils.buildArtifactRepository( repo, artifactRepositoryFactory, container ); |
| 631 | |
|
| 632 | 0 | normalized.add( item ); |
| 633 | 0 | normalizationNeeded = true; |
| 634 | |
} |
| 635 | 0 | catch ( InvalidRepositoryException e ) |
| 636 | |
{ |
| 637 | 0 | throw new ProjectBuildingException( projectId, "Error building artifact repository for id: " + repo.getId(), e ); |
| 638 | 0 | } |
| 639 | 0 | } |
| 640 | |
else |
| 641 | |
{ |
| 642 | 0 | throw new ProjectBuildingException( projectId, "Error building artifact repository from non-repository information item: " + item ); |
| 643 | |
} |
| 644 | 0 | } |
| 645 | |
|
| 646 | 0 | if ( normalizationNeeded ) |
| 647 | |
{ |
| 648 | 0 | return normalized; |
| 649 | |
} |
| 650 | |
else |
| 651 | |
{ |
| 652 | 0 | return remoteArtifactRepositories; |
| 653 | |
} |
| 654 | |
} |
| 655 | |
|
| 656 | |
private void checkStatusAndUpdate( Artifact projectArtifact, |
| 657 | |
ArtifactStatus status, |
| 658 | |
File file, |
| 659 | |
List remoteArtifactRepositories, |
| 660 | |
ArtifactRepository localRepository ) |
| 661 | |
throws ArtifactNotFoundException |
| 662 | |
{ |
| 663 | |
|
| 664 | 0 | if ( !projectArtifact.isSnapshot() && ( status.compareTo( ArtifactStatus.DEPLOYED ) < 0 ) ) |
| 665 | |
{ |
| 666 | |
|
| 667 | 0 | ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(); |
| 668 | |
|
| 669 | 0 | policy.setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); |
| 670 | |
|
| 671 | 0 | if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) ) |
| 672 | |
{ |
| 673 | 0 | getLogger().info( |
| 674 | |
projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" ); |
| 675 | |
try |
| 676 | |
{ |
| 677 | 0 | projectArtifact.setResolved( false ); |
| 678 | 0 | artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories, localRepository ); |
| 679 | |
} |
| 680 | 0 | catch ( ArtifactResolutionException e ) |
| 681 | |
{ |
| 682 | 0 | getLogger().warn( "Error updating POM - using existing version" ); |
| 683 | 0 | getLogger().debug( "Cause", e ); |
| 684 | |
} |
| 685 | 0 | catch ( ArtifactNotFoundException e ) |
| 686 | |
{ |
| 687 | 0 | getLogger().warn( "Error updating POM - not found. Removing local copy." ); |
| 688 | 0 | getLogger().debug( "Cause", e ); |
| 689 | 0 | file.delete(); |
| 690 | 0 | throw e; |
| 691 | 0 | } |
| 692 | |
} |
| 693 | |
} |
| 694 | 0 | } |
| 695 | |
|
| 696 | |
|
| 697 | |
|
| 698 | |
|
| 699 | |
private Model createStubModel( Artifact projectArtifact ) |
| 700 | |
{ |
| 701 | 0 | getLogger().debug( "Using defaults for missing POM " + projectArtifact ); |
| 702 | |
|
| 703 | 0 | Model model = new Model(); |
| 704 | |
|
| 705 | 0 | model.setModelVersion( "4.0.0" ); |
| 706 | |
|
| 707 | 0 | model.setArtifactId( projectArtifact.getArtifactId() ); |
| 708 | |
|
| 709 | 0 | model.setGroupId( projectArtifact.getGroupId() ); |
| 710 | |
|
| 711 | 0 | model.setVersion( projectArtifact.getVersion() ); |
| 712 | |
|
| 713 | |
|
| 714 | 0 | model.setPackaging( projectArtifact.getType() ); |
| 715 | |
|
| 716 | 0 | model.setDistributionManagement( new DistributionManagement() ); |
| 717 | |
|
| 718 | 0 | model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() ); |
| 719 | |
|
| 720 | 0 | return model; |
| 721 | |
} |
| 722 | |
|
| 723 | |
|
| 724 | |
|
| 725 | |
|
| 726 | |
private MavenProject buildInternal( String pomLocation, |
| 727 | |
Model model, |
| 728 | |
ProjectBuilderConfiguration config, |
| 729 | |
List parentSearchRepositories, |
| 730 | |
File projectDescriptor, |
| 731 | |
boolean strict ) |
| 732 | |
throws ProjectBuildingException |
| 733 | |
{ |
| 734 | 0 | File projectDir = null; |
| 735 | |
|
| 736 | 0 | if ( projectDescriptor != null ) |
| 737 | |
{ |
| 738 | 0 | projectDir = projectDescriptor.getAbsoluteFile().getParentFile(); |
| 739 | |
} |
| 740 | |
|
| 741 | 0 | Model superModel = getSuperModel(); |
| 742 | |
|
| 743 | 0 | ProfileManager externalProfileManager = config.getGlobalProfileManager(); |
| 744 | |
ProfileManager superProjectProfileManager; |
| 745 | 0 | if ( externalProfileManager != null ) |
| 746 | |
{ |
| 747 | 0 | superProjectProfileManager = new DefaultProfileManager( |
| 748 | |
container, |
| 749 | |
externalProfileManager.getRequestProperties() ); |
| 750 | |
} |
| 751 | |
else |
| 752 | |
{ |
| 753 | 0 | superProjectProfileManager = new DefaultProfileManager( container ); |
| 754 | |
} |
| 755 | |
|
| 756 | |
List activeProfiles; |
| 757 | |
|
| 758 | 0 | superProjectProfileManager.addProfiles( superModel.getProfiles() ); |
| 759 | |
|
| 760 | 0 | activeProfiles = injectActiveProfiles( superProjectProfileManager, superModel ); |
| 761 | |
|
| 762 | 0 | MavenProject superProject = new MavenProject( superModel ); |
| 763 | |
|
| 764 | 0 | superProject.setActiveProfiles( activeProfiles ); |
| 765 | |
|
| 766 | |
|
| 767 | 0 | LinkedList lineage = new LinkedList(); |
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
|
| 772 | |
|
| 773 | 0 | Set aggregatedRemoteWagonRepositories = new LinkedHashSet(); |
| 774 | |
|
| 775 | 0 | String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); |
| 776 | |
|
| 777 | |
List activeExternalProfiles; |
| 778 | |
try |
| 779 | |
{ |
| 780 | 0 | if ( externalProfileManager != null ) |
| 781 | |
{ |
| 782 | 0 | activeExternalProfiles = externalProfileManager.getActiveProfiles(); |
| 783 | |
} |
| 784 | |
else |
| 785 | |
{ |
| 786 | 0 | activeExternalProfiles = Collections.EMPTY_LIST; |
| 787 | |
} |
| 788 | |
} |
| 789 | 0 | catch ( ProfileActivationException e ) |
| 790 | |
{ |
| 791 | 0 | throw new ProjectBuildingException( projectId, "Failed to calculate active external profiles.", e ); |
| 792 | 0 | } |
| 793 | |
|
| 794 | 0 | for ( Iterator i = activeExternalProfiles.iterator(); i.hasNext(); ) |
| 795 | |
{ |
| 796 | 0 | Profile externalProfile = (Profile) i.next(); |
| 797 | |
|
| 798 | 0 | for ( Iterator repoIterator = externalProfile.getRepositories().iterator(); repoIterator.hasNext(); ) |
| 799 | |
{ |
| 800 | 0 | Repository mavenRepo = (Repository) repoIterator.next(); |
| 801 | |
|
| 802 | 0 | ArtifactRepository artifactRepo = null; |
| 803 | |
try |
| 804 | |
{ |
| 805 | 0 | artifactRepo = |
| 806 | |
ProjectUtils.buildArtifactRepository( mavenRepo, artifactRepositoryFactory, container ); |
| 807 | |
} |
| 808 | 0 | catch ( InvalidRepositoryException e ) |
| 809 | |
{ |
| 810 | 0 | throw new ProjectBuildingException( projectId, e.getMessage(), e ); |
| 811 | 0 | } |
| 812 | |
|
| 813 | 0 | aggregatedRemoteWagonRepositories.add( artifactRepo ); |
| 814 | 0 | } |
| 815 | 0 | } |
| 816 | |
|
| 817 | 0 | MavenProject project = null; |
| 818 | |
try |
| 819 | |
{ |
| 820 | 0 | project = assembleLineage( model, lineage, config, projectDescriptor, parentSearchRepositories, |
| 821 | |
aggregatedRemoteWagonRepositories, strict ); |
| 822 | |
} |
| 823 | 0 | catch ( InvalidRepositoryException e ) |
| 824 | |
{ |
| 825 | 0 | throw new ProjectBuildingException( projectId, e.getMessage(), e ); |
| 826 | 0 | } |
| 827 | |
|
| 828 | |
|
| 829 | 0 | MavenProject previousProject = superProject; |
| 830 | |
|
| 831 | 0 | Model previous = superProject.getModel(); |
| 832 | |
|
| 833 | 0 | for ( Iterator i = lineage.iterator(); i.hasNext(); ) |
| 834 | |
{ |
| 835 | 0 | MavenProject currentProject = (MavenProject) i.next(); |
| 836 | |
|
| 837 | 0 | Model current = currentProject.getModel(); |
| 838 | |
|
| 839 | 0 | String pathAdjustment = null; |
| 840 | |
|
| 841 | |
try |
| 842 | |
{ |
| 843 | 0 | pathAdjustment = previousProject.getModulePathAdjustment( currentProject ); |
| 844 | |
} |
| 845 | 0 | catch ( IOException e ) |
| 846 | |
{ |
| 847 | 0 | getLogger().debug( "Cannot determine whether " + currentProject.getId() + " is a module of " + |
| 848 | |
previousProject.getId() + ". Reason: " + e.getMessage(), e ); |
| 849 | 0 | } |
| 850 | |
|
| 851 | 0 | modelInheritanceAssembler.assembleModelInheritance( current, previous, pathAdjustment ); |
| 852 | |
|
| 853 | 0 | previous = current; |
| 854 | 0 | previousProject = currentProject; |
| 855 | 0 | } |
| 856 | |
|
| 857 | |
|
| 858 | 0 | List repositories = new ArrayList( aggregatedRemoteWagonRepositories ); |
| 859 | |
|
| 860 | 0 | List superRepositories = buildArtifactRepositories( superModel ); |
| 861 | |
|
| 862 | 0 | for ( Iterator i = superRepositories.iterator(); i.hasNext(); ) |
| 863 | |
{ |
| 864 | 0 | ArtifactRepository repository = (ArtifactRepository) i.next(); |
| 865 | |
|
| 866 | 0 | if ( !repositories.contains( repository ) ) |
| 867 | |
{ |
| 868 | 0 | repositories.add( repository ); |
| 869 | |
} |
| 870 | 0 | } |
| 871 | |
|
| 872 | |
|
| 873 | 0 | ModelUtils.mergeDuplicatePluginDefinitions( project.getModel().getBuild() ); |
| 874 | |
|
| 875 | |
try |
| 876 | |
{ |
| 877 | 0 | project = processProjectLogic( pomLocation, project, config, projectDir, repositories, strict, false ); |
| 878 | |
} |
| 879 | 0 | catch ( ModelInterpolationException e ) |
| 880 | |
{ |
| 881 | 0 | throw new InvalidProjectModelException( projectId, pomLocation, e.getMessage(), e ); |
| 882 | |
} |
| 883 | 0 | catch ( InvalidRepositoryException e ) |
| 884 | |
{ |
| 885 | 0 | throw new InvalidProjectModelException( projectId, pomLocation, e.getMessage(), e ); |
| 886 | 0 | } |
| 887 | |
|
| 888 | 0 | processedProjectCache.put( |
| 889 | |
createCacheKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project ); |
| 890 | |
|
| 891 | |
|
| 892 | |
|
| 893 | 0 | if ( projectDescriptor != null ) |
| 894 | |
{ |
| 895 | |
|
| 896 | 0 | pathTranslator.alignToBaseDirectory( project.getModel(), |
| 897 | |
projectDir ); |
| 898 | |
|
| 899 | 0 | Build build = project.getBuild(); |
| 900 | |
|
| 901 | 0 | project.addCompileSourceRoot( build.getSourceDirectory() ); |
| 902 | |
|
| 903 | 0 | project.addScriptSourceRoot( build.getScriptSourceDirectory() ); |
| 904 | |
|
| 905 | 0 | project.addTestCompileSourceRoot( build.getTestSourceDirectory() ); |
| 906 | |
|
| 907 | |
|
| 908 | 0 | project.setFile( projectDescriptor ); |
| 909 | |
} |
| 910 | |
|
| 911 | 0 | project.setManagedVersionMap( createManagedVersionMap( projectId, |
| 912 | |
project.getDependencyManagement(), |
| 913 | |
project.getParent() ) ); |
| 914 | |
|
| 915 | 0 | return project; |
| 916 | |
} |
| 917 | |
|
| 918 | |
private String safeVersionlessKey( String groupId, |
| 919 | |
String artifactId ) |
| 920 | |
{ |
| 921 | 0 | String gid = groupId; |
| 922 | |
|
| 923 | 0 | if ( StringUtils.isEmpty( gid ) ) |
| 924 | |
{ |
| 925 | 0 | gid = "unknown"; |
| 926 | |
} |
| 927 | |
|
| 928 | 0 | String aid = artifactId; |
| 929 | |
|
| 930 | 0 | if ( StringUtils.isEmpty( aid ) ) |
| 931 | |
{ |
| 932 | 0 | aid = "unknown"; |
| 933 | |
} |
| 934 | |
|
| 935 | 0 | return ArtifactUtils.versionlessKey( gid, aid ); |
| 936 | |
} |
| 937 | |
|
| 938 | |
private List buildArtifactRepositories( Model model ) |
| 939 | |
throws ProjectBuildingException |
| 940 | |
{ |
| 941 | |
try |
| 942 | |
{ |
| 943 | 0 | return ProjectUtils.buildArtifactRepositories( model.getRepositories(), artifactRepositoryFactory, |
| 944 | |
container ); |
| 945 | |
} |
| 946 | 0 | catch ( InvalidRepositoryException e ) |
| 947 | |
{ |
| 948 | 0 | String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); |
| 949 | |
|
| 950 | 0 | throw new ProjectBuildingException( projectId, e.getMessage(), e ); |
| 951 | |
} |
| 952 | |
} |
| 953 | |
|
| 954 | |
|
| 955 | |
|
| 956 | |
|
| 957 | |
|
| 958 | |
|
| 959 | |
|
| 960 | |
|
| 961 | |
private MavenProject processProjectLogic( String pomLocation, |
| 962 | |
MavenProject project, |
| 963 | |
ProjectBuilderConfiguration config, |
| 964 | |
File projectDir, |
| 965 | |
List remoteRepositories, |
| 966 | |
boolean strict, |
| 967 | |
boolean isSuperPom ) |
| 968 | |
throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException |
| 969 | |
{ |
| 970 | 0 | Model model = project.getModel(); |
| 971 | |
|
| 972 | 0 | List activeProfiles = project.getActiveProfiles(); |
| 973 | |
|
| 974 | 0 | if ( activeProfiles == null ) |
| 975 | |
{ |
| 976 | 0 | activeProfiles = new ArrayList(); |
| 977 | |
} |
| 978 | |
|
| 979 | 0 | ProfileManager profileMgr = config == null ? null : config.getGlobalProfileManager(); |
| 980 | |
|
| 981 | 0 | List injectedProfiles = injectActiveProfiles( profileMgr, model ); |
| 982 | |
|
| 983 | 0 | activeProfiles.addAll( injectedProfiles ); |
| 984 | |
|
| 985 | |
|
| 986 | 0 | Map context = new HashMap(); |
| 987 | |
|
| 988 | |
|
| 989 | |
|
| 990 | 0 | Build build = model.getBuild(); |
| 991 | |
|
| 992 | 0 | if ( projectDir != null ) |
| 993 | |
{ |
| 994 | 0 | context.put( "basedir", projectDir.getAbsolutePath() ); |
| 995 | |
|
| 996 | |
|
| 997 | |
|
| 998 | |
|
| 999 | |
|
| 1000 | |
|
| 1001 | 0 | context.put( "build.directory", pathTranslator.alignToBaseDirectory( build.getDirectory(), projectDir ) ); |
| 1002 | 0 | context.put( "build.outputDirectory", pathTranslator.alignToBaseDirectory( build.getOutputDirectory(), projectDir ) ); |
| 1003 | 0 | context.put( "build.testOutputDirectory", pathTranslator.alignToBaseDirectory( build.getTestOutputDirectory(), projectDir ) ); |
| 1004 | 0 | context.put( "build.sourceDirectory", pathTranslator.alignToBaseDirectory( build.getSourceDirectory(), projectDir ) ); |
| 1005 | 0 | context.put( "build.testSourceDirectory", pathTranslator.alignToBaseDirectory( build.getTestSourceDirectory(), projectDir ) ); |
| 1006 | |
} |
| 1007 | |
|
| 1008 | 0 | if ( !isSuperPom ) |
| 1009 | |
{ |
| 1010 | 0 | Properties userProps = config.getUserProperties(); |
| 1011 | 0 | if ( userProps != null ) |
| 1012 | |
{ |
| 1013 | 0 | context.putAll( userProps ); |
| 1014 | |
} |
| 1015 | |
} |
| 1016 | |
|
| 1017 | 0 | model = modelInterpolator.interpolate( model, context, strict ); |
| 1018 | |
|
| 1019 | |
|
| 1020 | |
|
| 1021 | 0 | if ( config.getExecutionProperties() != null && !config.getExecutionProperties().isEmpty() ) |
| 1022 | |
{ |
| 1023 | 0 | context.putAll( config.getExecutionProperties() ); |
| 1024 | |
} |
| 1025 | |
|
| 1026 | 0 | model = modelInterpolator.interpolate( model, context, strict ); |
| 1027 | |
|
| 1028 | |
|
| 1029 | 0 | if ( !isSuperPom ) |
| 1030 | |
{ |
| 1031 | 0 | mergeManagedDependencies( model, config.getLocalRepository(), remoteRepositories ); |
| 1032 | |
} |
| 1033 | |
|
| 1034 | |
|
| 1035 | 0 | modelDefaultsInjector.injectDefaults( model ); |
| 1036 | |
|
| 1037 | 0 | MavenProject parentProject = project.getParent(); |
| 1038 | |
|
| 1039 | 0 | Model originalModel = project.getOriginalModel(); |
| 1040 | |
|
| 1041 | |
|
| 1042 | 0 | project = new MavenProject( model ); |
| 1043 | |
|
| 1044 | 0 | project.setOriginalModel( originalModel ); |
| 1045 | |
|
| 1046 | 0 | project.setActiveProfiles( activeProfiles ); |
| 1047 | |
|
| 1048 | |
|
| 1049 | 0 | Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), |
| 1050 | |
project.getVersion(), project.getPackaging() ); |
| 1051 | |
|
| 1052 | 0 | project.setArtifact( projectArtifact ); |
| 1053 | |
|
| 1054 | 0 | project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(), |
| 1055 | |
artifactRepositoryFactory, |
| 1056 | |
container ) ); |
| 1057 | |
|
| 1058 | 0 | DistributionManagement dm = model.getDistributionManagement(); |
| 1059 | 0 | if ( dm != null ) |
| 1060 | |
{ |
| 1061 | 0 | ArtifactRepository repo = ProjectUtils.buildDeploymentArtifactRepository( dm.getRepository(), |
| 1062 | |
artifactRepositoryFactory, |
| 1063 | |
container ); |
| 1064 | 0 | project.setReleaseArtifactRepository( repo ); |
| 1065 | |
|
| 1066 | 0 | if ( dm.getSnapshotRepository() != null ) |
| 1067 | |
{ |
| 1068 | 0 | repo = ProjectUtils.buildDeploymentArtifactRepository( dm.getSnapshotRepository(), |
| 1069 | |
artifactRepositoryFactory, container ); |
| 1070 | 0 | project.setSnapshotArtifactRepository( repo ); |
| 1071 | |
} |
| 1072 | |
} |
| 1073 | |
|
| 1074 | 0 | if ( parentProject != null ) |
| 1075 | |
{ |
| 1076 | 0 | String cacheKey = createCacheKey( parentProject.getGroupId(), |
| 1077 | |
parentProject.getArtifactId(), |
| 1078 | |
parentProject.getVersion() ); |
| 1079 | |
|
| 1080 | 0 | MavenProject processedParent = (MavenProject) processedProjectCache.get( cacheKey ); |
| 1081 | |
Artifact parentArtifact; |
| 1082 | |
|
| 1083 | |
|
| 1084 | 0 | if ( processedParent != null ) |
| 1085 | |
{ |
| 1086 | 0 | project.setParent( processedParent ); |
| 1087 | |
|
| 1088 | 0 | parentArtifact = processedParent.getArtifact(); |
| 1089 | |
} |
| 1090 | |
else |
| 1091 | |
{ |
| 1092 | 0 | project.setParent( parentProject ); |
| 1093 | |
|
| 1094 | 0 | parentArtifact = artifactFactory.createParentArtifact( parentProject.getGroupId(), |
| 1095 | |
parentProject.getArtifactId(), |
| 1096 | |
parentProject.getVersion() ); |
| 1097 | |
} |
| 1098 | |
|
| 1099 | 0 | project.setParentArtifact( parentArtifact ); |
| 1100 | |
} |
| 1101 | |
|
| 1102 | |
|
| 1103 | 0 | ModelValidationResult validationResult = validator.validate( model ); |
| 1104 | |
|
| 1105 | 0 | String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); |
| 1106 | |
|
| 1107 | 0 | if ( validationResult.getMessageCount() > 0 ) |
| 1108 | |
{ |
| 1109 | 0 | throw new InvalidProjectModelException( projectId, pomLocation, "Failed to validate POM", |
| 1110 | |
validationResult ); |
| 1111 | |
} |
| 1112 | |
|
| 1113 | 0 | project.setRemoteArtifactRepositories( |
| 1114 | |
ProjectUtils.buildArtifactRepositories( model.getRepositories(), artifactRepositoryFactory, container ) ); |
| 1115 | |
|
| 1116 | |
|
| 1117 | 0 | project.setPluginArtifacts( createPluginArtifacts( projectId, project.getBuildPlugins() ) ); |
| 1118 | |
|
| 1119 | 0 | project.setReportArtifacts( createReportArtifacts( projectId, project.getReportPlugins() ) ); |
| 1120 | |
|
| 1121 | 0 | project.setExtensionArtifacts( createExtensionArtifacts( projectId, project.getBuildExtensions() ) ); |
| 1122 | |
|
| 1123 | 0 | return project; |
| 1124 | |
} |
| 1125 | |
|
| 1126 | |
|
| 1127 | |
|
| 1128 | |
|
| 1129 | |
|
| 1130 | |
|
| 1131 | |
private MavenProject assembleLineage( Model model, |
| 1132 | |
LinkedList lineage, |
| 1133 | |
ProjectBuilderConfiguration config, |
| 1134 | |
File projectDescriptor, |
| 1135 | |
List parentSearchRepositories, |
| 1136 | |
Set aggregatedRemoteWagonRepositories, |
| 1137 | |
boolean strict ) |
| 1138 | |
throws ProjectBuildingException, InvalidRepositoryException |
| 1139 | |
{ |
| 1140 | 0 | Model originalModel = ModelUtils.cloneModel( model ); |
| 1141 | |
|
| 1142 | 0 | File projectDir = null; |
| 1143 | 0 | if ( projectDescriptor != null ) |
| 1144 | |
{ |
| 1145 | 0 | projectDir = projectDescriptor.getAbsoluteFile().getParentFile(); |
| 1146 | |
} |
| 1147 | |
|
| 1148 | 0 | ProfileManager externalProfileManager = config.getGlobalProfileManager(); |
| 1149 | |
ProfileManager profileManager; |
| 1150 | 0 | if ( externalProfileManager != null ) |
| 1151 | |
{ |
| 1152 | 0 | profileManager = new DefaultProfileManager( container, externalProfileManager.getRequestProperties() ); |
| 1153 | |
} |
| 1154 | |
else |
| 1155 | |
{ |
| 1156 | |
|
| 1157 | 0 | profileManager = new DefaultProfileManager( container ); |
| 1158 | |
} |
| 1159 | |
|
| 1160 | 0 | if ( externalProfileManager != null ) |
| 1161 | |
{ |
| 1162 | 0 | profileManager.explicitlyActivate( externalProfileManager.getExplicitlyActivatedIds() ); |
| 1163 | |
|
| 1164 | 0 | profileManager.explicitlyDeactivate( externalProfileManager.getExplicitlyDeactivatedIds() ); |
| 1165 | |
} |
| 1166 | |
|
| 1167 | |
List activeProfiles; |
| 1168 | |
|
| 1169 | |
try |
| 1170 | |
{ |
| 1171 | 0 | profileManager.addProfiles( model.getProfiles() ); |
| 1172 | |
|
| 1173 | 0 | loadProjectExternalProfiles( profileManager, projectDir ); |
| 1174 | |
|
| 1175 | 0 | activeProfiles = injectActiveProfiles( profileManager, model ); |
| 1176 | |
} |
| 1177 | 0 | catch ( ProfileActivationException e ) |
| 1178 | |
{ |
| 1179 | 0 | String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); |
| 1180 | |
|
| 1181 | 0 | throw new ProjectBuildingException( projectId, "Failed to activate local (project-level) build profiles: " + |
| 1182 | |
e.getMessage(), e ); |
| 1183 | 0 | } |
| 1184 | |
|
| 1185 | 0 | if ( !model.getRepositories().isEmpty() ) |
| 1186 | |
{ |
| 1187 | 0 | List respositories = buildArtifactRepositories( model ); |
| 1188 | |
|
| 1189 | 0 | for ( Iterator it = respositories.iterator(); it.hasNext(); ) |
| 1190 | |
{ |
| 1191 | 0 | ArtifactRepository repository = (ArtifactRepository) it.next(); |
| 1192 | |
|
| 1193 | 0 | if ( !aggregatedRemoteWagonRepositories.contains( repository ) ) |
| 1194 | |
{ |
| 1195 | 0 | aggregatedRemoteWagonRepositories.add( repository ); |
| 1196 | |
} |
| 1197 | 0 | } |
| 1198 | |
} |
| 1199 | |
|
| 1200 | 0 | MavenProject project = new MavenProject( model ); |
| 1201 | |
|
| 1202 | 0 | project.setFile( projectDescriptor ); |
| 1203 | 0 | project.setActiveProfiles( activeProfiles ); |
| 1204 | 0 | project.setOriginalModel( originalModel ); |
| 1205 | |
|
| 1206 | 0 | lineage.addFirst( project ); |
| 1207 | |
|
| 1208 | 0 | Parent parentModel = model.getParent(); |
| 1209 | |
|
| 1210 | 0 | String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); |
| 1211 | |
|
| 1212 | 0 | if ( parentModel != null ) |
| 1213 | |
{ |
| 1214 | 0 | if ( StringUtils.isEmpty( parentModel.getGroupId() ) ) |
| 1215 | |
{ |
| 1216 | 0 | throw new ProjectBuildingException( projectId, "Missing groupId element from parent element" ); |
| 1217 | |
} |
| 1218 | 0 | else if ( StringUtils.isEmpty( parentModel.getArtifactId() ) ) |
| 1219 | |
{ |
| 1220 | 0 | throw new ProjectBuildingException( projectId, "Missing artifactId element from parent element" ); |
| 1221 | |
} |
| 1222 | 0 | else if ( parentModel.getGroupId().equals( model.getGroupId() ) && |
| 1223 | |
parentModel.getArtifactId().equals( model.getArtifactId() ) ) |
| 1224 | |
{ |
| 1225 | 0 | throw new ProjectBuildingException( projectId, |
| 1226 | |
"Parent element is a duplicate of " + "the current project " ); |
| 1227 | |
} |
| 1228 | 0 | else if ( StringUtils.isEmpty( parentModel.getVersion() ) ) |
| 1229 | |
{ |
| 1230 | 0 | throw new ProjectBuildingException( projectId, "Missing version element from parent element" ); |
| 1231 | |
} |
| 1232 | |
|
| 1233 | |
|
| 1234 | 0 | File parentDescriptor = null; |
| 1235 | |
|
| 1236 | 0 | model = null; |
| 1237 | |
|
| 1238 | 0 | String parentKey = |
| 1239 | |
createCacheKey( parentModel.getGroupId(), parentModel.getArtifactId(), parentModel.getVersion() ); |
| 1240 | 0 | MavenProject parentProject = (MavenProject) rawProjectCache.get( parentKey ); |
| 1241 | |
|
| 1242 | 0 | if ( parentProject != null ) |
| 1243 | |
{ |
| 1244 | 0 | model = ModelUtils.cloneModel( parentProject.getOriginalModel() ); |
| 1245 | |
|
| 1246 | 0 | parentDescriptor = parentProject.getFile(); |
| 1247 | |
} |
| 1248 | |
|
| 1249 | 0 | String parentRelativePath = parentModel.getRelativePath(); |
| 1250 | |
|
| 1251 | |
|
| 1252 | |
|
| 1253 | 0 | if ( ( model == null ) && ( projectDir != null ) && StringUtils.isNotEmpty( parentRelativePath ) ) |
| 1254 | |
{ |
| 1255 | 0 | parentDescriptor = new File( projectDir, parentRelativePath ); |
| 1256 | |
|
| 1257 | 0 | if ( getLogger().isDebugEnabled() ) |
| 1258 | |
{ |
| 1259 | 0 | getLogger().debug( "Searching for parent-POM: " + parentModel.getId() + " of project: " + |
| 1260 | |
project.getId() + " in relative path: " + parentRelativePath ); |
| 1261 | |
} |
| 1262 | |
|
| 1263 | 0 | if ( parentDescriptor.isDirectory() ) |
| 1264 | |
{ |
| 1265 | 0 | if ( getLogger().isDebugEnabled() ) |
| 1266 | |
{ |
| 1267 | 0 | getLogger().debug( "Path specified in <relativePath/> (" + parentRelativePath + |
| 1268 | |
") is a directory. Searching for 'pom.xml' within this directory." ); |
| 1269 | |
} |
| 1270 | |
|
| 1271 | 0 | parentDescriptor = new File( parentDescriptor, "pom.xml" ); |
| 1272 | |
|
| 1273 | 0 | if ( !parentDescriptor.exists() ) |
| 1274 | |
{ |
| 1275 | 0 | if ( getLogger().isDebugEnabled() ) |
| 1276 | |
{ |
| 1277 | 0 | getLogger().debug( "Parent-POM: " + parentModel.getId() + " for project: " + |
| 1278 | |
project.getId() + " cannot be loaded from relative path: " + parentDescriptor + |
| 1279 | |
"; path does not exist." ); |
| 1280 | |
} |
| 1281 | |
} |
| 1282 | |
} |
| 1283 | |
|
| 1284 | 0 | if ( parentDescriptor != null ) |
| 1285 | |
{ |
| 1286 | |
try |
| 1287 | |
{ |
| 1288 | 0 | parentDescriptor = parentDescriptor.getCanonicalFile(); |
| 1289 | |
} |
| 1290 | 0 | catch ( IOException e ) |
| 1291 | |
{ |
| 1292 | 0 | getLogger().debug( "Failed to canonicalize potential parent POM: \'" + parentDescriptor + "\'", |
| 1293 | |
e ); |
| 1294 | |
|
| 1295 | 0 | parentDescriptor = null; |
| 1296 | 0 | } |
| 1297 | |
} |
| 1298 | |
|
| 1299 | 0 | if ( ( parentDescriptor != null ) && parentDescriptor.exists() ) |
| 1300 | |
{ |
| 1301 | 0 | Model candidateParent = readModel( projectId, parentDescriptor, strict ); |
| 1302 | |
|
| 1303 | 0 | String candidateParentGroupId = candidateParent.getGroupId(); |
| 1304 | 0 | if ( ( candidateParentGroupId == null ) && ( candidateParent.getParent() != null ) ) |
| 1305 | |
{ |
| 1306 | 0 | candidateParentGroupId = candidateParent.getParent().getGroupId(); |
| 1307 | |
} |
| 1308 | |
|
| 1309 | 0 | String candidateParentVersion = candidateParent.getVersion(); |
| 1310 | 0 | if ( ( candidateParentVersion == null ) && ( candidateParent.getParent() != null ) ) |
| 1311 | |
{ |
| 1312 | 0 | candidateParentVersion = candidateParent.getParent().getVersion(); |
| 1313 | |
} |
| 1314 | |
|
| 1315 | 0 | if ( parentModel.getGroupId().equals( candidateParentGroupId ) && |
| 1316 | |
parentModel.getArtifactId().equals( candidateParent.getArtifactId() ) && |
| 1317 | |
parentModel.getVersion().equals( candidateParentVersion ) ) |
| 1318 | |
{ |
| 1319 | 0 | model = candidateParent; |
| 1320 | |
|
| 1321 | 0 | getLogger().debug( "Using parent-POM from the project hierarchy at: \'" + |
| 1322 | |
parentModel.getRelativePath() + "\' for project: " + project.getId() ); |
| 1323 | |
} |
| 1324 | |
else |
| 1325 | |
{ |
| 1326 | 0 | getLogger().debug( "Invalid parent-POM referenced by relative path '" + |
| 1327 | |
parentModel.getRelativePath() + "' in parent specification in " + project.getId() + ":" + |
| 1328 | |
"\n Specified: " + parentModel.getId() + "\n Found: " + candidateParent.getId() ); |
| 1329 | |
} |
| 1330 | 0 | } |
| 1331 | 0 | else if ( getLogger().isDebugEnabled() ) |
| 1332 | |
{ |
| 1333 | 0 | getLogger().debug( |
| 1334 | |
"Parent-POM: " + parentModel.getId() + " not found in relative path: " + parentRelativePath ); |
| 1335 | |
} |
| 1336 | |
} |
| 1337 | |
|
| 1338 | 0 | Artifact parentArtifact = null; |
| 1339 | |
|
| 1340 | |
|
| 1341 | 0 | if ( model == null ) |
| 1342 | |
{ |
| 1343 | |
|
| 1344 | |
|
| 1345 | 0 | parentDescriptor = null; |
| 1346 | |
|
| 1347 | |
|
| 1348 | |
|
| 1349 | |
|
| 1350 | |
|
| 1351 | |
|
| 1352 | |
|
| 1353 | |
|
| 1354 | |
|
| 1355 | |
|
| 1356 | |
|
| 1357 | |
|
| 1358 | 0 | List remoteRepositories = new ArrayList( aggregatedRemoteWagonRepositories ); |
| 1359 | 0 | remoteRepositories.addAll( parentSearchRepositories ); |
| 1360 | |
|
| 1361 | 0 | if ( getLogger().isDebugEnabled() ) |
| 1362 | |
{ |
| 1363 | 0 | getLogger().debug( "Retrieving parent-POM: " + parentModel.getId() + " for project: " + |
| 1364 | |
project.getId() + " from the repository." ); |
| 1365 | |
} |
| 1366 | |
|
| 1367 | 0 | parentArtifact = artifactFactory.createParentArtifact( parentModel.getGroupId(), |
| 1368 | |
parentModel.getArtifactId(), |
| 1369 | |
parentModel.getVersion() ); |
| 1370 | |
|
| 1371 | |
try |
| 1372 | |
{ |
| 1373 | 0 | model = findModelFromRepository( parentArtifact, remoteRepositories, config.getLocalRepository(), false ); |
| 1374 | |
} |
| 1375 | 0 | catch ( ProjectBuildingException e ) |
| 1376 | |
{ |
| 1377 | 0 | throw new ProjectBuildingException( project.getId(), "Cannot find parent: " + e.getProjectId() + |
| 1378 | |
" for project: " + project.getId(), e ); |
| 1379 | 0 | } |
| 1380 | |
} |
| 1381 | |
|
| 1382 | 0 | if ( ( model != null ) && !"pom".equals( model.getPackaging() ) ) |
| 1383 | |
{ |
| 1384 | 0 | throw new ProjectBuildingException( projectId, "Parent: " + model.getId() + " of project: " + |
| 1385 | |
projectId + " has wrong packaging: " + model.getPackaging() + ". Must be 'pom'." ); |
| 1386 | |
} |
| 1387 | |
|
| 1388 | 0 | MavenProject parent = assembleLineage( model, |
| 1389 | |
lineage, |
| 1390 | |
config, |
| 1391 | |
parentDescriptor, |
| 1392 | |
parentSearchRepositories, |
| 1393 | |
aggregatedRemoteWagonRepositories, |
| 1394 | |
strict ); |
| 1395 | |
|
| 1396 | 0 | project.setParent( parent ); |
| 1397 | |
|
| 1398 | 0 | project.setParentArtifact( parentArtifact ); |
| 1399 | |
} |
| 1400 | |
|
| 1401 | 0 | rawProjectCache.put( createCacheKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ), new MavenProject( project ) ); |
| 1402 | |
|
| 1403 | 0 | return project; |
| 1404 | |
} |
| 1405 | |
|
| 1406 | |
private void mergeManagedDependencies(Model model, ArtifactRepository localRepository, List parentSearchRepositories) |
| 1407 | |
throws ProjectBuildingException |
| 1408 | |
{ |
| 1409 | 0 | DependencyManagement modelDepMgmt = model.getDependencyManagement(); |
| 1410 | |
|
| 1411 | 0 | if (modelDepMgmt != null) |
| 1412 | |
{ |
| 1413 | 0 | Map depsMap = new TreeMap(); |
| 1414 | 0 | Iterator iter = modelDepMgmt.getDependencies().iterator(); |
| 1415 | 0 | boolean doInclude = false; |
| 1416 | 0 | while (iter.hasNext()) |
| 1417 | |
{ |
| 1418 | 0 | Dependency dep = (Dependency) iter.next(); |
| 1419 | 0 | depsMap.put( dep.getManagementKey(), dep ); |
| 1420 | 0 | if ( dep.getType().equals( "pom" ) && Artifact.SCOPE_IMPORT.equals( dep.getScope() ) ) |
| 1421 | |
{ |
| 1422 | 0 | doInclude = true; |
| 1423 | |
} |
| 1424 | 0 | } |
| 1425 | 0 | Map newDeps = new TreeMap(depsMap); |
| 1426 | 0 | iter = modelDepMgmt.getDependencies().iterator(); |
| 1427 | 0 | if (doInclude) |
| 1428 | |
{ |
| 1429 | 0 | while (iter.hasNext()) |
| 1430 | |
{ |
| 1431 | 0 | Dependency dep = (Dependency)iter.next(); |
| 1432 | 0 | if ( dep.getType().equals( "pom" ) |
| 1433 | |
&& Artifact.SCOPE_IMPORT.equals( dep.getScope() ) ) |
| 1434 | |
{ |
| 1435 | 0 | Artifact artifact = artifactFactory.createProjectArtifact( dep.getGroupId(), dep.getArtifactId(), |
| 1436 | |
dep.getVersion(), dep.getScope() ); |
| 1437 | 0 | MavenProject project = buildFromRepository(artifact, parentSearchRepositories, localRepository, false); |
| 1438 | |
|
| 1439 | 0 | DependencyManagement depMgmt = project.getDependencyManagement(); |
| 1440 | |
|
| 1441 | 0 | if (depMgmt != null) |
| 1442 | |
{ |
| 1443 | 0 | if ( getLogger().isDebugEnabled() ) |
| 1444 | |
{ |
| 1445 | 0 | getLogger().debug( "Importing managed dependencies for " + dep.toString() ); |
| 1446 | |
} |
| 1447 | |
|
| 1448 | 0 | for ( Iterator it = depMgmt.getDependencies().iterator(); it.hasNext(); ) |
| 1449 | |
{ |
| 1450 | 0 | Dependency includedDep = (Dependency) it.next(); |
| 1451 | 0 | String key = includedDep.getManagementKey(); |
| 1452 | 0 | if (!newDeps.containsKey(key)) |
| 1453 | |
{ |
| 1454 | 0 | newDeps.put( includedDep.getManagementKey(), includedDep ); |
| 1455 | |
} |
| 1456 | 0 | } |
| 1457 | 0 | newDeps.remove(dep.getManagementKey()); |
| 1458 | |
} |
| 1459 | |
} |
| 1460 | 0 | } |
| 1461 | 0 | List deps = new ArrayList(newDeps.values()); |
| 1462 | 0 | modelDepMgmt.setDependencies(deps); |
| 1463 | |
} |
| 1464 | |
} |
| 1465 | 0 | } |
| 1466 | |
|
| 1467 | |
private List injectActiveProfiles( ProfileManager profileManager, |
| 1468 | |
Model model ) |
| 1469 | |
throws ProjectBuildingException |
| 1470 | |
{ |
| 1471 | |
List activeProfiles; |
| 1472 | |
|
| 1473 | 0 | if ( profileManager != null ) |
| 1474 | |
{ |
| 1475 | |
try |
| 1476 | |
{ |
| 1477 | 0 | activeProfiles = profileManager.getActiveProfiles(); |
| 1478 | |
} |
| 1479 | 0 | catch ( ProfileActivationException e ) |
| 1480 | |
{ |
| 1481 | 0 | String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); |
| 1482 | |
|
| 1483 | 0 | throw new ProjectBuildingException( projectId, e.getMessage(), e ); |
| 1484 | 0 | } |
| 1485 | |
|
| 1486 | 0 | for ( Iterator it = activeProfiles.iterator(); it.hasNext(); ) |
| 1487 | |
{ |
| 1488 | 0 | Profile profile = (Profile) it.next(); |
| 1489 | |
|
| 1490 | 0 | profileInjector.inject( profile, model ); |
| 1491 | 0 | } |
| 1492 | |
} |
| 1493 | |
else |
| 1494 | |
{ |
| 1495 | 0 | activeProfiles = Collections.EMPTY_LIST; |
| 1496 | |
} |
| 1497 | |
|
| 1498 | 0 | return activeProfiles; |
| 1499 | |
} |
| 1500 | |
|
| 1501 | |
private void loadProjectExternalProfiles( ProfileManager profileManager, |
| 1502 | |
File projectDir ) |
| 1503 | |
throws ProfileActivationException |
| 1504 | |
{ |
| 1505 | 0 | if ( projectDir != null ) |
| 1506 | |
{ |
| 1507 | |
try |
| 1508 | |
{ |
| 1509 | 0 | ProfilesRoot root = profilesBuilder.buildProfiles( projectDir ); |
| 1510 | |
|
| 1511 | 0 | if ( root != null ) |
| 1512 | |
{ |
| 1513 | 0 | List active = root.getActiveProfiles(); |
| 1514 | |
|
| 1515 | 0 | if ( ( active != null ) && !active.isEmpty() ) |
| 1516 | |
{ |
| 1517 | 0 | profileManager.explicitlyActivate( root.getActiveProfiles() ); |
| 1518 | |
} |
| 1519 | |
|
| 1520 | 0 | for ( Iterator it = root.getProfiles().iterator(); it.hasNext(); ) |
| 1521 | |
{ |
| 1522 | 0 | org.apache.maven.profiles.Profile rawProfile = (org.apache.maven.profiles.Profile) it.next(); |
| 1523 | |
|
| 1524 | 0 | Profile converted = ProfilesConversionUtils.convertFromProfileXmlProfile( rawProfile ); |
| 1525 | |
|
| 1526 | 0 | profileManager.addProfile( converted ); |
| 1527 | 0 | } |
| 1528 | |
} |
| 1529 | |
} |
| 1530 | 0 | catch ( IOException e ) |
| 1531 | |
{ |
| 1532 | 0 | throw new ProfileActivationException( "Cannot read profiles.xml resource from directory: " + projectDir, |
| 1533 | |
e ); |
| 1534 | |
} |
| 1535 | 0 | catch ( XmlPullParserException e ) |
| 1536 | |
{ |
| 1537 | 0 | throw new ProfileActivationException( |
| 1538 | |
"Cannot parse profiles.xml resource from directory: " + projectDir, e ); |
| 1539 | 0 | } |
| 1540 | |
} |
| 1541 | 0 | } |
| 1542 | |
|
| 1543 | |
private Model readModel( String projectId, |
| 1544 | |
File file, |
| 1545 | |
boolean strict ) |
| 1546 | |
throws ProjectBuildingException |
| 1547 | |
{ |
| 1548 | 0 | Reader reader = null; |
| 1549 | |
try |
| 1550 | |
{ |
| 1551 | 0 | reader = ReaderFactory.newXmlReader( file ); |
| 1552 | 0 | return readModel( projectId, file.getAbsolutePath(), reader, strict ); |
| 1553 | |
} |
| 1554 | 0 | catch ( FileNotFoundException e ) |
| 1555 | |
{ |
| 1556 | 0 | throw new ProjectBuildingException( projectId, |
| 1557 | |
"Could not find the model file '" + file.getAbsolutePath() + "'.", e ); |
| 1558 | |
} |
| 1559 | 0 | catch ( IOException e ) |
| 1560 | |
{ |
| 1561 | 0 | throw new ProjectBuildingException( projectId, "Failed to build model from file '" + |
| 1562 | |
file.getAbsolutePath() + "'.\nError: \'" + e.getLocalizedMessage() + "\'", e ); |
| 1563 | |
} |
| 1564 | |
finally |
| 1565 | |
{ |
| 1566 | 0 | IOUtil.close( reader ); |
| 1567 | |
} |
| 1568 | |
} |
| 1569 | |
|
| 1570 | |
private Model readModel( String projectId, |
| 1571 | |
String pomLocation, |
| 1572 | |
Reader reader, |
| 1573 | |
boolean strict ) |
| 1574 | |
throws IOException, InvalidProjectModelException |
| 1575 | |
{ |
| 1576 | 0 | String modelSource = IOUtil.toString( reader ); |
| 1577 | |
|
| 1578 | 0 | if ( modelSource.indexOf( "<modelVersion>" + MAVEN_MODEL_VERSION ) < 0 ) |
| 1579 | |
{ |
| 1580 | 0 | throw new InvalidProjectModelException( projectId, pomLocation, "Not a v" + MAVEN_MODEL_VERSION + " POM." ); |
| 1581 | |
} |
| 1582 | |
|
| 1583 | 0 | StringReader sReader = new StringReader( modelSource ); |
| 1584 | |
|
| 1585 | |
try |
| 1586 | |
{ |
| 1587 | 0 | return modelReader.read( sReader, strict ); |
| 1588 | |
} |
| 1589 | 0 | catch ( XmlPullParserException e ) |
| 1590 | |
{ |
| 1591 | 0 | throw new InvalidProjectModelException( projectId, pomLocation, |
| 1592 | |
"Parse error reading POM. Reason: " + e.getMessage(), e ); |
| 1593 | |
} |
| 1594 | |
} |
| 1595 | |
|
| 1596 | |
private Model readModel( String projectId, |
| 1597 | |
URL url, |
| 1598 | |
boolean strict ) |
| 1599 | |
throws ProjectBuildingException |
| 1600 | |
{ |
| 1601 | 0 | Reader reader = null; |
| 1602 | |
try |
| 1603 | |
{ |
| 1604 | 0 | reader = ReaderFactory.newXmlReader( url.openStream() ); |
| 1605 | 0 | return readModel( projectId, url.toExternalForm(), reader, strict ); |
| 1606 | |
} |
| 1607 | 0 | catch ( IOException e ) |
| 1608 | |
{ |
| 1609 | 0 | throw new ProjectBuildingException( projectId, "Failed build model from URL \'" + url.toExternalForm() + |
| 1610 | |
"\'\nError: \'" + e.getLocalizedMessage() + "\'", e ); |
| 1611 | |
} |
| 1612 | |
finally |
| 1613 | |
{ |
| 1614 | 0 | IOUtil.close( reader ); |
| 1615 | |
} |
| 1616 | |
} |
| 1617 | |
|
| 1618 | |
private static String createCacheKey( String groupId, |
| 1619 | |
String artifactId, |
| 1620 | |
String version ) |
| 1621 | |
{ |
| 1622 | 0 | return groupId + ":" + artifactId + ":" + version; |
| 1623 | |
} |
| 1624 | |
|
| 1625 | |
protected Set createPluginArtifacts( String projectId, |
| 1626 | |
List plugins ) |
| 1627 | |
throws ProjectBuildingException |
| 1628 | |
{ |
| 1629 | 0 | Set pluginArtifacts = new LinkedHashSet(); |
| 1630 | |
|
| 1631 | 0 | for ( Iterator i = plugins.iterator(); i.hasNext(); ) |
| 1632 | |
{ |
| 1633 | 0 | Plugin p = (Plugin) i.next(); |
| 1634 | |
|
| 1635 | |
String version; |
| 1636 | 0 | if ( StringUtils.isEmpty( p.getVersion() ) ) |
| 1637 | |
{ |
| 1638 | 0 | version = "RELEASE"; |
| 1639 | |
} |
| 1640 | |
else |
| 1641 | |
{ |
| 1642 | 0 | version = p.getVersion(); |
| 1643 | |
} |
| 1644 | |
|
| 1645 | |
Artifact artifact; |
| 1646 | |
try |
| 1647 | |
{ |
| 1648 | 0 | artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(), |
| 1649 | |
VersionRange.createFromVersionSpec( version ) ); |
| 1650 | |
} |
| 1651 | 0 | catch ( InvalidVersionSpecificationException e ) |
| 1652 | |
{ |
| 1653 | 0 | throw new ProjectBuildingException( projectId, "Unable to parse version '" + version + |
| 1654 | |
"' for plugin '" + ArtifactUtils.versionlessKey( p.getGroupId(), p.getArtifactId() ) + "': " + |
| 1655 | |
e.getMessage(), e ); |
| 1656 | 0 | } |
| 1657 | |
|
| 1658 | 0 | if ( artifact != null ) |
| 1659 | |
{ |
| 1660 | 0 | pluginArtifacts.add( artifact ); |
| 1661 | |
} |
| 1662 | 0 | } |
| 1663 | |
|
| 1664 | 0 | return pluginArtifacts; |
| 1665 | |
} |
| 1666 | |
|
| 1667 | |
|
| 1668 | |
protected Set createReportArtifacts( String projectId, |
| 1669 | |
List reports ) |
| 1670 | |
throws ProjectBuildingException |
| 1671 | |
{ |
| 1672 | 0 | Set pluginArtifacts = new LinkedHashSet(); |
| 1673 | |
|
| 1674 | 0 | if ( reports != null ) |
| 1675 | |
{ |
| 1676 | 0 | for ( Iterator i = reports.iterator(); i.hasNext(); ) |
| 1677 | |
{ |
| 1678 | 0 | ReportPlugin p = (ReportPlugin) i.next(); |
| 1679 | |
|
| 1680 | |
String version; |
| 1681 | 0 | if ( StringUtils.isEmpty( p.getVersion() ) ) |
| 1682 | |
{ |
| 1683 | 0 | version = "RELEASE"; |
| 1684 | |
} |
| 1685 | |
else |
| 1686 | |
{ |
| 1687 | 0 | version = p.getVersion(); |
| 1688 | |
} |
| 1689 | |
|
| 1690 | |
Artifact artifact; |
| 1691 | |
try |
| 1692 | |
{ |
| 1693 | 0 | artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(), |
| 1694 | |
VersionRange.createFromVersionSpec( version ) ); |
| 1695 | |
} |
| 1696 | 0 | catch ( InvalidVersionSpecificationException e ) |
| 1697 | |
{ |
| 1698 | 0 | throw new ProjectBuildingException( projectId, "Unable to parse version '" + version + |
| 1699 | |
"' for report '" + ArtifactUtils.versionlessKey( p.getGroupId(), p.getArtifactId() ) + "': " + |
| 1700 | |
e.getMessage(), e ); |
| 1701 | 0 | } |
| 1702 | |
|
| 1703 | 0 | if ( artifact != null ) |
| 1704 | |
{ |
| 1705 | 0 | pluginArtifacts.add( artifact ); |
| 1706 | |
} |
| 1707 | 0 | } |
| 1708 | |
} |
| 1709 | |
|
| 1710 | 0 | return pluginArtifacts; |
| 1711 | |
} |
| 1712 | |
|
| 1713 | |
|
| 1714 | |
protected Set createExtensionArtifacts( String projectId, |
| 1715 | |
List extensions ) |
| 1716 | |
throws ProjectBuildingException |
| 1717 | |
{ |
| 1718 | 0 | Set extensionArtifacts = new LinkedHashSet(); |
| 1719 | |
|
| 1720 | 0 | if ( extensions != null ) |
| 1721 | |
{ |
| 1722 | 0 | for ( Iterator i = extensions.iterator(); i.hasNext(); ) |
| 1723 | |
{ |
| 1724 | 0 | Extension ext = (Extension) i.next(); |
| 1725 | |
|
| 1726 | |
String version; |
| 1727 | 0 | if ( StringUtils.isEmpty( ext.getVersion() ) ) |
| 1728 | |
{ |
| 1729 | 0 | version = "RELEASE"; |
| 1730 | |
} |
| 1731 | |
else |
| 1732 | |
{ |
| 1733 | 0 | version = ext.getVersion(); |
| 1734 | |
} |
| 1735 | |
|
| 1736 | |
Artifact artifact; |
| 1737 | |
try |
| 1738 | |
{ |
| 1739 | 0 | VersionRange versionRange = VersionRange.createFromVersionSpec( version ); |
| 1740 | 0 | artifact = |
| 1741 | |
artifactFactory.createExtensionArtifact( ext.getGroupId(), ext.getArtifactId(), versionRange ); |
| 1742 | |
} |
| 1743 | 0 | catch ( InvalidVersionSpecificationException e ) |
| 1744 | |
{ |
| 1745 | 0 | throw new ProjectBuildingException( projectId, "Unable to parse version '" + version + |
| 1746 | |
"' for extension '" + ArtifactUtils.versionlessKey( ext.getGroupId(), ext.getArtifactId() ) + |
| 1747 | |
"': " + e.getMessage(), e ); |
| 1748 | 0 | } |
| 1749 | |
|
| 1750 | 0 | if ( artifact != null ) |
| 1751 | |
{ |
| 1752 | 0 | extensionArtifacts.add( artifact ); |
| 1753 | |
} |
| 1754 | 0 | } |
| 1755 | |
} |
| 1756 | |
|
| 1757 | 0 | return extensionArtifacts; |
| 1758 | |
} |
| 1759 | |
|
| 1760 | |
|
| 1761 | |
|
| 1762 | |
|
| 1763 | |
|
| 1764 | |
private Model getSuperModel() |
| 1765 | |
throws ProjectBuildingException |
| 1766 | |
{ |
| 1767 | 0 | URL url = DefaultMavenProjectBuilder.class.getResource( "pom-" + MAVEN_MODEL_VERSION + ".xml" ); |
| 1768 | |
|
| 1769 | 0 | String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID ); |
| 1770 | |
|
| 1771 | 0 | return readModel( projectId, url, true ); |
| 1772 | |
} |
| 1773 | |
|
| 1774 | |
public void contextualize( Context context ) |
| 1775 | |
throws ContextException |
| 1776 | |
{ |
| 1777 | 0 | container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); |
| 1778 | 0 | } |
| 1779 | |
|
| 1780 | |
} |