You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2024/04/12 10:50:25 UTC
(maven) branch master updated (84e2d8ad3f -> d075fe7e85)
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
from 84e2d8ad3f [MNG-8084] Include repository metadata in the API (#1465)
new 9be08ccef8 [MNG-8084] Include lifecycle in the API
new d075fe7e85 [MNG-8084] New model builder and resolver provider
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../maven/api/{Packaging.java => Lifecycle.java} | 52 +-
.../main/java/org/apache/maven/api/Packaging.java | 8 +-
.../main/java/org/apache/maven/api/PathScope.java | 1 +
.../maven/api/plugin/annotations/Execute.java | 13 +-
.../api/plugin/annotations/LifecyclePhase.java | 74 -
.../apache/maven/api/plugin/annotations/Mojo.java | 2 +-
.../LifecycleRegistry.java} | 24 +-
.../ModelBuilder.java} | 26 +-
.../maven/api/services/ModelBuilderException.java | 80 +
.../maven/api/services/ModelBuilderRequest.java | 454 +++++
.../maven/api/services/ModelBuilderResult.java | 125 ++
.../apache/maven/api/services/ModelProblem.java | 57 +
.../maven/api/services/ModelProblemCollector.java | 67 +
.../apache/maven/api/services/ModelResolver.java | 125 ++
.../maven/api/services/ModelResolverException.java | 114 ++
.../org/apache/maven/api/services/ModelSource.java | 59 +
.../{TypeRegistry.java => ModelTransformer.java} | 27 +-
.../api/services/ModelTransformerContext.java | 66 +
...ry.java => ModelTransformerContextBuilder.java} | 28 +-
.../ModelTransformerException.java} | 19 +-
.../org/apache/maven/api/services/PathSource.java | 33 +-
.../java/org/apache/maven/api/services/Source.java | 3 +-
.../apache/maven/api/services/TypeRegistry.java | 5 +-
api/maven-api-metadata/pom.xml | 2 +-
.../apache/maven/api/spi/LifecycleProvider.java} | 16 +-
.../java/org/apache/maven/api/spi/ModelParser.java | 5 +
maven-api-impl/pom.xml | 86 +-
.../model/DependencyManagementImporter.java | 47 +
.../model/DependencyManagementInjector.java | 40 +
.../api/services/model/InheritanceAssembler.java | 44 +
.../services/model/LifecycleBindingsInjector.java | 42 +
.../api/services/model/ModelBuildingEvent.java | 55 +
.../api/services/model/ModelBuildingListener.java | 22 +-
.../maven/api/services/model/ModelCache.java | 38 +
.../api/services/model/ModelInterpolator.java | 48 +
.../maven/api/services/model/ModelNormalizer.java | 50 +
.../api/services/model/ModelPathTranslator.java | 29 +-
.../maven/api/services/model/ModelProcessor.java | 52 +
.../api/services/model/ModelUrlNormalizer.java | 25 +-
.../maven/api/services/model/ModelValidator.java | 61 +
.../api/services/model/ModelVersionParser.java | 70 +
.../api/services/model/ModelVersionProcessor.java | 33 +-
.../maven/api/services/model/PathTranslator.java | 27 +-
.../model/PluginConfigurationExpander.java | 39 +
.../services/model/PluginManagementInjector.java | 40 +
.../services/model/ProfileActivationContext.java | 81 +
.../maven/api/services/model/ProfileActivator.java | 54 +
.../maven/api/services/model/ProfileInjector.java | 59 +
.../maven/api/services/model/ProfileSelector.java | 45 +
.../maven/api/services/model/RootLocator.java | 67 +
.../maven/api/services/model/UrlNormalizer.java | 21 +-
.../api/services/model/WorkspaceModelResolver.java | 18 +-
.../maven/internal/impl/AbstractSession.java | 3 +-
.../maven/internal/impl/DefaultArtifact.java | 1 -
.../maven/internal/impl/DefaultDependency.java | 1 -
.../internal/impl/DefaultModelUrlNormalizer.java | 80 +
.../internal/impl/DefaultModelVersionParser.java | 288 ++++
.../internal/impl/DefaultModelXmlFactory.java | 3 +-
.../impl/DefaultPluginConfigurationExpander.java | 107 ++
.../internal/impl/DefaultRemoteRepository.java | 5 +
.../internal/impl/DefaultSettingsBuilder.java | 40 +-
.../internal/impl/DefaultSuperPomProvider.java | 80 +
.../maven/internal/impl/DefaultUrlNormalizer.java | 61 +
.../maven/internal/impl/DefaultVersionParser.java | 2 +-
.../internal/impl/DefaultVersionRangeResolver.java | 5 +-
.../internal/impl/ExtensibleEnumRegistries.java | 36 +-
.../maven/internal/impl/InternalSession.java | 4 +
.../java/org/apache/maven/internal/impl/Utils.java | 3 +
.../internal/impl/model/BuildModelTransformer.java | 199 +++
.../model/DefaultDependencyManagementImporter.java | 147 ++
.../model/DefaultDependencyManagementInjector.java | 119 ++
.../impl/model/DefaultInheritanceAssembler.java | 330 ++++
.../model}/DefaultLifecycleBindingsInjector.java | 110 +-
.../internal/impl/model/DefaultModelBuilder.java | 1410 ++++++++++++++++
.../impl/model/DefaultModelBuilderResult.java | 222 +++
.../impl/model/DefaultModelBuildingEvent.java | 22 +-
.../impl/model/DefaultModelInterpolator.java | 485 ++++++
.../impl/model/DefaultModelNormalizer.java | 147 ++
.../impl/model/DefaultModelPathTranslator.java | 121 ++
.../internal/impl/model/DefaultModelProblem.java | 182 ++
.../impl/model/DefaultModelProblemCollector.java | 198 +++
.../internal/impl/model/DefaultModelProcessor.java | 142 ++
.../impl/model/DefaultModelTransformerContext.java | 141 ++
.../DefaultModelTransformerContextBuilder.java | 231 +++
.../internal/impl/model/DefaultModelValidator.java | 1742 ++++++++++++++++++++
.../impl/model/DefaultModelVersionProcessor.java | 63 +
.../internal/impl/model/DefaultPathTranslator.java | 58 +
.../model/DefaultPluginManagementInjector.java | 128 ++
.../model/DefaultProfileActivationContext.java | 190 +++
.../impl/model/DefaultProfileInjector.java | 242 +++
.../impl/model/DefaultProfileSelector.java | 123 ++
.../internal/impl/model/DefaultRootLocator.java | 61 +
.../internal/impl/model/FileToRawModelMerger.java | 216 +++
.../apache/maven/internal/impl/model/Graph.java | 96 ++
.../internal/impl/model/MavenBuildTimestamp.java | 80 +
.../internal/impl/model}/MavenModelMerger.java | 27 +-
.../maven/internal/impl/model/ModelData.java | 38 +-
.../internal/impl/model/ModelProblemUtils.java | 133 ++
.../ProfileActivationFilePathInterpolator.java | 100 ++
.../apache/maven/internal/impl/model/Result.java | 230 +++
.../impl/model/profile/FileProfileActivator.java | 123 ++
.../model/profile/JdkVersionProfileActivator.java | 188 +++
.../profile/OperatingSystemProfileActivator.java | 154 ++
.../maven/internal/impl/model/profile/Os.java | 233 +++
.../model/profile/PackagingProfileActivator.java | 57 +
.../model/profile/PropertyProfileActivator.java | 104 ++
.../resolver/ArtifactDescriptorReaderDelegate.java | 149 ++
.../impl/resolver/ArtifactDescriptorUtils.java | 94 ++
.../resolver/DefaultArtifactDescriptorReader.java | 299 ++++
.../internal/impl/resolver/DefaultModelCache.java | 210 +++
.../impl/resolver/DefaultModelResolver.java | 251 +++
.../resolver}/DefaultVersionRangeResolver.java | 37 +-
.../impl/resolver}/DefaultVersionResolver.java | 34 +-
.../resolver/DefaultVersionSchemeProvider.java | 33 +-
.../impl/resolver/LocalSnapshotMetadata.java | 142 ++
.../resolver/LocalSnapshotMetadataGenerator.java | 77 +
.../resolver/MavenArtifactRelocationSource.java | 45 +
.../internal/impl/resolver}/MavenMetadata.java | 25 +-
.../impl/resolver/MavenSessionBuilderSupplier.java | 152 ++
.../impl/resolver/MavenSnapshotMetadata.java | 84 +
.../impl/resolver/MavenWorkspaceReader.java | 18 +-
.../internal/impl/resolver/PluginsMetadata.java | 115 ++
.../impl/resolver/PluginsMetadataGenerator.java | 145 ++
.../resolver/PluginsMetadataGeneratorFactory.java | 52 +
.../internal/impl/resolver/RelocatedArtifact.java | 174 ++
.../impl/resolver/RemoteSnapshotMetadata.java | 148 ++
.../resolver/RemoteSnapshotMetadataGenerator.java | 108 ++
.../resolver/SnapshotMetadataGeneratorFactory.java | 52 +
.../internal/impl/resolver/VersionsMetadata.java | 133 ++
.../impl/resolver/VersionsMetadataGenerator.java | 103 ++
.../resolver/VersionsMetadataGeneratorFactory.java | 52 +
.../resolver/artifact/FatArtifactTraverser.java | 67 +
.../resolver/artifact/MavenArtifactProperties.java | 56 +
.../maven/internal/impl/resolver/package-info.java | 6 +
...ributionManagementArtifactRelocationSource.java | 76 +
.../UserPropertiesArtifactRelocationSource.java | 215 +++
.../scopes/Maven3ScopeManagerConfiguration.java | 169 ++
.../scopes/Maven4ScopeManagerConfiguration.java | 197 +++
.../internal/impl/resolver/type/DefaultType.java | 114 ++
.../impl/resolver/type/DefaultTypeProvider.java | 67 +
.../resources/org/apache/maven/model/pom-4.0.0.xml | 0
.../resources/org/apache/maven/model/pom-4.1.0.xml | 0
.../internal/impl/model}/MavenModelMergerTest.java | 2 +-
.../maven/internal/impl/standalone/ApiRunner.java | 194 ++-
.../maven/internal/impl/standalone/DiTest.java | 29 +-
.../impl/standalone/RepositorySystemSupplier.java | 113 +-
.../impl/standalone/TestApiStandalone.java | 9 +
.../metadata/AbstractRepositoryMetadata.java | 4 +-
.../metadata/DefaultRepositoryMetadataManager.java | 4 +-
.../maven/AbstractCoreMavenComponentTestCase.java | 14 +-
.../AbstractArtifactComponentTestCase.java | 4 +-
.../project/AbstractMavenProjectTestCase.java | 17 +
.../project/EmptyLifecycleBindingsInjector.java | 163 ++
.../project/EmptyLifecyclePluginAnalyzer.java | 67 -
.../maven/project/ProjectClasspathTestType.java | 2 +-
.../apache/maven/project/TestProjectBuilder.java | 4 +-
.../AbstractProjectInheritanceTestCase.java | 9 +
.../inheritance/t02/ProjectInheritanceTest.java | 3 +
.../repository/LegacyRepositorySystemTest.java | 9 +-
.../META-INF/maven/org.apache.maven.api.di.Inject | 1 +
.../maven/project/AbstractMavenProjectTestCase.xml | 9 -
maven-core/pom.xml | 1 +
.../main/java/org/apache/maven/DefaultMaven.java | 2 +-
.../main/java/org/apache/maven/ReactorReader.java | 6 +-
.../metadata/io/DefaultMetadataReader.java | 1 +
.../execution/DefaultMavenExecutionRequest.java | 3 +-
.../DefaultRepositorySystemSessionFactory.java | 9 +-
.../LegacyRepositorySystemSessionExtender.java | 7 +-
.../internal/impl/DefaultLifecycleRegistry.java | 235 +++
.../internal/impl/DefaultPackagingRegistry.java | 38 +-
.../apache/maven/internal/impl/DefaultSession.java | 33 +-
.../maven/internal/impl/DefaultSessionFactory.java | 9 +-
.../apache/maven/internal/impl/EventSpyImpl.java | 3 +-
.../java/org/apache/maven/internal/impl/Graph.java | 145 ++
.../org/apache/maven/internal/impl/Lifecycles.java | 73 +
.../maven/internal/impl/SisuDiBridgeModule.java | 194 ++-
.../impl/DefaultConsumerPomBuilder.java | 167 +-
.../apache/maven/lifecycle/DefaultLifecycles.java | 16 +-
.../java/org/apache/maven/lifecycle/Lifecycle.java | 29 +-
.../providers/CleanLifecycleProvider.java | 47 -
.../providers/DefaultLifecycleProvider.java | 70 -
.../lifecycle/providers/SiteLifecycleProvider.java | 48 -
.../plugin/DefaultLifecycleBindingsInjector.java | 6 +-
.../DefaultPluginDependenciesResolver.java | 7 +-
.../project/DefaultModelBuildingListener.java | 49 +-
.../maven/project/DefaultProjectBuilder.java | 551 +++++--
.../DefaultProjectDependenciesResolver.java | 11 +-
.../org/apache/maven/project/ProjectBuilder.java | 13 +
.../apache/maven/project/ProjectModelResolver.java | 13 +-
.../org/apache/maven/project/ReactorModelPool.java | 2 +-
.../resolver/MavenChainedWorkspaceReader.java | 4 +-
.../maven/AbstractCoreMavenComponentTestCase.java | 16 +-
.../java/org/apache/maven/DefaultMavenTest.java | 6 +-
.../java/org/apache/maven/MavenTestHelper.java | 36 +
.../org/apache/maven/internal/impl/TestApi.java | 1 -
.../transformation/AbstractRepositoryTestCase.java | 18 +-
.../impl/ConsumerPomBuilderTest.java | 6 +
.../maven/lifecycle/DefaultLifecyclesTest.java | 5 +-
.../internal/stub/DefaultLifecyclesStub.java | 4 +-
.../org/apache/maven/model/ModelBuilderTest.java | 22 +-
.../project/AbstractMavenProjectTestCase.java | 19 +
.../project/EmptyLifecycleBindingsInjector.java | 163 ++
.../apache/maven/project/PomConstructionTest.java | 4 +-
.../settings/PomConstructionWithSettingsTest.java | 3 +-
.../META-INF/maven/org.apache.maven.api.di.Inject | 1 +
.../org/apache/maven/di/impl/InjectorImpl.java | 52 +-
.../main/java/org/apache/maven/di/impl/Types.java | 20 +-
.../internal/BootstrapCoreExtensionManager.java | 65 +-
maven-model-builder/pom.xml | 4 +
.../model/building/DefaultModelProcessor.java | 3 +-
.../apache/maven/model/locator/ModelLocator.java | 5 +-
.../apache/maven/model/merge/MavenModelMerger.java | 594 +------
maven-model/pom.xml | 21 +-
maven-repository-metadata/pom.xml | 20 +-
.../metadata/io/xpp3/MetadataXpp3Reader.java | 2 +-
.../metadata/io/xpp3/MetadataXpp3Writer.java | 2 +-
.../artifact/repository/metadata/MetadataTest.java | 4 +-
.../internal/DefaultVersionRangeResolver.java | 2 +-
.../internal/DefaultVersionResolver.java | 2 +-
.../maven/repository/internal/MavenMetadata.java | 4 +-
.../maven/internal/xml/XmlNodeStaxBuilder.java | 7 +
221 files changed, 17346 insertions(+), 1902 deletions(-)
copy api/maven-api-core/src/main/java/org/apache/maven/api/{Packaging.java => Lifecycle.java} (57%)
delete mode 100644 api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/LifecyclePhase.java
copy api/maven-api-core/src/main/java/org/apache/maven/api/{MetadataStorage.java => services/LifecycleRegistry.java} (65%)
copy api/maven-api-core/src/main/java/org/apache/maven/api/{MetadataStorage.java => services/ModelBuilder.java} (63%)
create mode 100644 api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderException.java
create mode 100644 api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java
create mode 100644 api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderResult.java
create mode 100644 api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelProblem.java
create mode 100644 api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelProblemCollector.java
create mode 100644 api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelResolver.java
create mode 100644 api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelResolverException.java
create mode 100644 api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelSource.java
copy api/maven-api-core/src/main/java/org/apache/maven/api/services/{TypeRegistry.java => ModelTransformer.java} (57%)
create mode 100644 api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformerContext.java
copy api/maven-api-core/src/main/java/org/apache/maven/api/services/{TypeRegistry.java => ModelTransformerContextBuilder.java} (55%)
copy api/maven-api-core/src/main/java/org/apache/maven/api/{MetadataStorage.java => services/ModelTransformerException.java} (73%)
copy api/{maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java => maven-api-spi/src/main/java/org/apache/maven/api/spi/LifecycleProvider.java} (80%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/DependencyManagementImporter.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/DependencyManagementInjector.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/InheritanceAssembler.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/LifecycleBindingsInjector.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelBuildingEvent.java
copy api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java => maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelBuildingListener.java (58%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelCache.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelInterpolator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelNormalizer.java
copy api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java => maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelPathTranslator.java (50%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelProcessor.java
copy api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java => maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelUrlNormalizer.java (57%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelValidator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelVersionParser.java
copy api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java => maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelVersionProcessor.java (52%)
copy api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java => maven-api-impl/src/main/java/org/apache/maven/api/services/model/PathTranslator.java (53%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/PluginConfigurationExpander.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/PluginManagementInjector.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileActivationContext.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileActivator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileInjector.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileSelector.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/api/services/model/RootLocator.java
copy api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java => maven-api-impl/src/main/java/org/apache/maven/api/services/model/UrlNormalizer.java (72%)
copy api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java => maven-api-impl/src/main/java/org/apache/maven/api/services/model/WorkspaceModelResolver.java (70%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelUrlNormalizer.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelVersionParser.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultPluginConfigurationExpander.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultSuperPomProvider.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultUrlNormalizer.java
rename {maven-core => maven-api-impl}/src/main/java/org/apache/maven/internal/impl/ExtensibleEnumRegistries.java (68%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/BuildModelTransformer.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultDependencyManagementImporter.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultDependencyManagementInjector.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultInheritanceAssembler.java
copy {maven-core/src/main/java/org/apache/maven/model/plugin => maven-api-impl/src/main/java/org/apache/maven/internal/impl/model}/DefaultLifecycleBindingsInjector.java (57%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilderResult.java
copy api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java => maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuildingEvent.java (60%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelNormalizer.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelPathTranslator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProblem.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProblemCollector.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProcessor.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContext.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContextBuilder.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelVersionProcessor.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultPathTranslator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultPluginManagementInjector.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultProfileActivationContext.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultProfileInjector.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultProfileSelector.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultRootLocator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/FileToRawModelMerger.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/Graph.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/MavenBuildTimestamp.java
copy {maven-model-builder/src/main/java/org/apache/maven/model/merge => maven-api-impl/src/main/java/org/apache/maven/internal/impl/model}/MavenModelMerger.java (95%)
rename maven-core/src/main/java/org/apache/maven/internal/impl/DefaultSuperPomProvider.java => maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/ModelData.java (51%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/ModelProblemUtils.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/ProfileActivationFilePathInterpolator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/Result.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/profile/FileProfileActivator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/profile/JdkVersionProfileActivator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/profile/OperatingSystemProfileActivator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/profile/Os.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/profile/PackagingProfileActivator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/profile/PropertyProfileActivator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/ArtifactDescriptorReaderDelegate.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/ArtifactDescriptorUtils.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultArtifactDescriptorReader.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultModelCache.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultModelResolver.java
copy {maven-resolver-provider/src/main/java/org/apache/maven/repository/internal => maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver}/DefaultVersionRangeResolver.java (92%)
copy {maven-resolver-provider/src/main/java/org/apache/maven/repository/internal => maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver}/DefaultVersionResolver.java (95%)
rename maven-core/src/main/java/org/apache/maven/lifecycle/providers/WrapperLifecycleProvider.java => maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultVersionSchemeProvider.java (51%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/LocalSnapshotMetadata.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/LocalSnapshotMetadataGenerator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenArtifactRelocationSource.java
copy {maven-resolver-provider/src/main/java/org/apache/maven/repository/internal => maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver}/MavenMetadata.java (85%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenSessionBuilderSupplier.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenSnapshotMetadata.java
copy api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java => maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenWorkspaceReader.java (72%)
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/PluginsMetadata.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/PluginsMetadataGenerator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/PluginsMetadataGeneratorFactory.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/RelocatedArtifact.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/RemoteSnapshotMetadata.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/RemoteSnapshotMetadataGenerator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/SnapshotMetadataGeneratorFactory.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/VersionsMetadata.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/VersionsMetadataGenerator.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/VersionsMetadataGeneratorFactory.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/artifact/FatArtifactTraverser.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/artifact/MavenArtifactProperties.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/package-info.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/relocation/DistributionManagementArtifactRelocationSource.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/relocation/UserPropertiesArtifactRelocationSource.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/scopes/Maven3ScopeManagerConfiguration.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/scopes/Maven4ScopeManagerConfiguration.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/type/DefaultType.java
create mode 100644 maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/type/DefaultTypeProvider.java
copy {maven-model-builder => maven-api-impl}/src/main/resources/org/apache/maven/model/pom-4.0.0.xml (100%)
copy {maven-model-builder => maven-api-impl}/src/main/resources/org/apache/maven/model/pom-4.1.0.xml (100%)
rename {maven-model-builder/src/test/java/org/apache/maven/model/merge => maven-api-impl/src/test/java/org/apache/maven/internal/impl/model}/MavenModelMergerTest.java (98%)
rename api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java => maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/DiTest.java (58%)
rename maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemSupplier.java => maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/RepositorySystemSupplier.java (90%)
create mode 100644 maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleBindingsInjector.java
delete mode 100644 maven-compat/src/test/java/org/apache/maven/project/EmptyLifecyclePluginAnalyzer.java
create mode 100644 maven-compat/src/test/resources/META-INF/maven/org.apache.maven.api.di.Inject
delete mode 100644 maven-compat/src/test/resources/org/apache/maven/project/AbstractMavenProjectTestCase.xml
create mode 100644 maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java
create mode 100644 maven-core/src/main/java/org/apache/maven/internal/impl/Graph.java
create mode 100644 maven-core/src/main/java/org/apache/maven/internal/impl/Lifecycles.java
delete mode 100644 maven-core/src/main/java/org/apache/maven/lifecycle/providers/CleanLifecycleProvider.java
delete mode 100644 maven-core/src/main/java/org/apache/maven/lifecycle/providers/DefaultLifecycleProvider.java
delete mode 100644 maven-core/src/main/java/org/apache/maven/lifecycle/providers/SiteLifecycleProvider.java
create mode 100644 maven-core/src/test/java/org/apache/maven/MavenTestHelper.java
create mode 100644 maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleBindingsInjector.java
create mode 100644 maven-core/src/test/resources/META-INF/maven/org.apache.maven.api.di.Inject
(maven) 02/02: [MNG-8084] New model builder and resolver provider
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
commit d075fe7e85d26d86ad25a963274cd9c5b910c56a
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Apr 11 08:22:55 2024 +0200
[MNG-8084] New model builder and resolver provider
---
.../main/java/org/apache/maven/api/Packaging.java | 8 +-
.../{TypeRegistry.java => ModelBuilder.java} | 32 +-
.../maven/api/services/ModelBuilderException.java | 80 +
.../maven/api/services/ModelBuilderRequest.java | 454 +++++
.../maven/api/services/ModelBuilderResult.java | 125 ++
.../apache/maven/api/services/ModelProblem.java | 57 +
.../maven/api/services/ModelProblemCollector.java | 67 +
.../apache/maven/api/services/ModelResolver.java | 125 ++
.../maven/api/services/ModelResolverException.java | 114 ++
.../org/apache/maven/api/services/ModelSource.java | 59 +
.../{TypeRegistry.java => ModelTransformer.java} | 27 +-
.../api/services/ModelTransformerContext.java | 66 +
...ry.java => ModelTransformerContextBuilder.java} | 28 +-
...egistry.java => ModelTransformerException.java} | 25 +-
.../org/apache/maven/api/services/PathSource.java | 33 +-
.../java/org/apache/maven/api/services/Source.java | 3 +-
.../apache/maven/api/services/TypeRegistry.java | 5 +-
api/maven-api-metadata/pom.xml | 2 +-
.../java/org/apache/maven/api/spi/ModelParser.java | 5 +
maven-api-impl/pom.xml | 86 +-
.../model/DependencyManagementImporter.java | 47 +
.../model/DependencyManagementInjector.java | 40 +
.../api/services/model/InheritanceAssembler.java | 44 +
.../services/model/LifecycleBindingsInjector.java | 42 +
.../api/services/model/ModelBuildingEvent.java | 55 +
.../api/services/model/ModelBuildingListener.java | 24 +-
.../maven/api/services/model/ModelCache.java | 38 +
.../api/services/model/ModelInterpolator.java | 48 +
.../maven/api/services/model/ModelNormalizer.java | 50 +
.../api/services/model/ModelPathTranslator.java | 29 +-
.../maven/api/services/model/ModelProcessor.java | 52 +
.../api/services/model/ModelUrlNormalizer.java | 25 +-
.../maven/api/services/model/ModelValidator.java | 61 +
.../api/services/model/ModelVersionParser.java | 70 +
.../api/services/model/ModelVersionProcessor.java | 33 +-
.../maven/api/services/model/PathTranslator.java | 27 +-
.../model/PluginConfigurationExpander.java | 39 +
.../services/model/PluginManagementInjector.java | 40 +
.../services/model/ProfileActivationContext.java | 81 +
.../maven/api/services/model/ProfileActivator.java | 54 +
.../maven/api/services/model/ProfileInjector.java | 59 +
.../maven/api/services/model/ProfileSelector.java | 45 +
.../maven/api/services/model/RootLocator.java | 67 +
.../maven/api/services/model/UrlNormalizer.java | 25 +-
.../api/services/model/WorkspaceModelResolver.java | 26 +-
.../maven/internal/impl/AbstractSession.java | 3 +-
.../maven/internal/impl/DefaultArtifact.java | 1 -
.../maven/internal/impl/DefaultDependency.java | 1 -
.../internal/impl/DefaultModelUrlNormalizer.java | 80 +
.../internal/impl/DefaultModelVersionParser.java | 288 ++++
.../internal/impl/DefaultModelXmlFactory.java | 3 +-
.../impl/DefaultPluginConfigurationExpander.java | 107 ++
.../internal/impl/DefaultRemoteRepository.java | 5 +
.../internal/impl/DefaultSettingsBuilder.java | 40 +-
.../internal/impl/DefaultSuperPomProvider.java | 80 +
.../maven/internal/impl/DefaultUrlNormalizer.java | 61 +
.../maven/internal/impl/DefaultVersionParser.java | 2 +-
.../internal/impl/DefaultVersionRangeResolver.java | 5 +-
.../internal/impl/ExtensibleEnumRegistries.java | 33 +-
.../maven/internal/impl/InternalSession.java | 4 +
.../java/org/apache/maven/internal/impl/Utils.java | 3 +
.../internal/impl/model/BuildModelTransformer.java | 199 +++
.../model/DefaultDependencyManagementImporter.java | 147 ++
.../model/DefaultDependencyManagementInjector.java | 119 ++
.../impl/model/DefaultInheritanceAssembler.java | 330 ++++
.../model}/DefaultLifecycleBindingsInjector.java | 110 +-
.../internal/impl/model/DefaultModelBuilder.java | 1410 ++++++++++++++++
.../impl/model/DefaultModelBuilderResult.java | 222 +++
.../impl/model/DefaultModelBuildingEvent.java | 32 +-
.../impl/model/DefaultModelInterpolator.java | 485 ++++++
.../impl/model/DefaultModelNormalizer.java | 147 ++
.../impl/model/DefaultModelPathTranslator.java | 121 ++
.../internal/impl/model/DefaultModelProblem.java | 182 ++
.../impl/model/DefaultModelProblemCollector.java | 198 +++
.../internal/impl/model/DefaultModelProcessor.java | 142 ++
.../impl/model/DefaultModelTransformerContext.java | 141 ++
.../DefaultModelTransformerContextBuilder.java | 231 +++
.../internal/impl/model/DefaultModelValidator.java | 1742 ++++++++++++++++++++
.../impl/model/DefaultModelVersionProcessor.java | 63 +
.../internal/impl/model/DefaultPathTranslator.java | 58 +
.../model/DefaultPluginManagementInjector.java | 128 ++
.../model/DefaultProfileActivationContext.java | 190 +++
.../impl/model/DefaultProfileInjector.java | 242 +++
.../impl/model/DefaultProfileSelector.java | 123 ++
.../internal/impl/model/DefaultRootLocator.java | 61 +
.../internal/impl/model/FileToRawModelMerger.java | 216 +++
.../apache/maven/internal/impl/model/Graph.java | 96 ++
.../internal/impl/model/MavenBuildTimestamp.java | 80 +
.../internal/impl/model}/MavenModelMerger.java | 27 +-
.../maven/internal/impl/model/ModelData.java | 38 +-
.../internal/impl/model/ModelProblemUtils.java | 133 ++
.../ProfileActivationFilePathInterpolator.java | 100 ++
.../apache/maven/internal/impl/model/Result.java | 230 +++
.../impl/model/profile/FileProfileActivator.java | 123 ++
.../model/profile/JdkVersionProfileActivator.java | 188 +++
.../profile/OperatingSystemProfileActivator.java | 154 ++
.../maven/internal/impl/model/profile/Os.java | 233 +++
.../model/profile/PackagingProfileActivator.java | 57 +
.../model/profile/PropertyProfileActivator.java | 104 ++
.../resolver/ArtifactDescriptorReaderDelegate.java | 149 ++
.../impl/resolver/ArtifactDescriptorUtils.java | 94 ++
.../resolver/DefaultArtifactDescriptorReader.java | 299 ++++
.../internal/impl/resolver/DefaultModelCache.java | 210 +++
.../impl/resolver/DefaultModelResolver.java | 251 +++
.../resolver}/DefaultVersionRangeResolver.java | 37 +-
.../impl/resolver}/DefaultVersionResolver.java | 34 +-
.../resolver/DefaultVersionSchemeProvider.java | 33 +-
.../impl/resolver/LocalSnapshotMetadata.java | 142 ++
.../resolver/LocalSnapshotMetadataGenerator.java | 77 +
.../resolver/MavenArtifactRelocationSource.java | 45 +
.../internal/impl/resolver}/MavenMetadata.java | 25 +-
.../impl/resolver/MavenSessionBuilderSupplier.java | 152 ++
.../impl/resolver/MavenSnapshotMetadata.java | 84 +
.../impl/resolver/MavenWorkspaceReader.java | 26 +-
.../internal/impl/resolver/PluginsMetadata.java | 115 ++
.../impl/resolver/PluginsMetadataGenerator.java | 145 ++
.../resolver/PluginsMetadataGeneratorFactory.java | 52 +
.../internal/impl/resolver/RelocatedArtifact.java | 174 ++
.../impl/resolver/RemoteSnapshotMetadata.java | 148 ++
.../resolver/RemoteSnapshotMetadataGenerator.java | 108 ++
.../resolver/SnapshotMetadataGeneratorFactory.java | 52 +
.../internal/impl/resolver/VersionsMetadata.java | 133 ++
.../impl/resolver/VersionsMetadataGenerator.java | 103 ++
.../resolver/VersionsMetadataGeneratorFactory.java | 52 +
.../resolver/artifact/FatArtifactTraverser.java | 67 +
.../resolver/artifact/MavenArtifactProperties.java | 56 +
.../maven/internal/impl/resolver/package-info.java | 6 +
...ributionManagementArtifactRelocationSource.java | 76 +
.../UserPropertiesArtifactRelocationSource.java | 215 +++
.../scopes/Maven3ScopeManagerConfiguration.java | 169 ++
.../scopes/Maven4ScopeManagerConfiguration.java | 197 +++
.../internal/impl/resolver/type/DefaultType.java | 114 ++
.../impl/resolver/type/DefaultTypeProvider.java | 67 +
.../resources/org/apache/maven/model/pom-4.0.0.xml | 64 +
.../resources/org/apache/maven/model/pom-4.1.0.xml | 64 +
.../internal/impl/model}/MavenModelMergerTest.java | 2 +-
.../maven/internal/impl/standalone/ApiRunner.java | 194 ++-
.../maven/internal/impl/standalone/DiTest.java | 37 +-
.../impl/standalone/RepositorySystemSupplier.java | 113 +-
.../impl/standalone/TestApiStandalone.java | 9 +
.../metadata/AbstractRepositoryMetadata.java | 4 +-
.../metadata/DefaultRepositoryMetadataManager.java | 4 +-
.../maven/AbstractCoreMavenComponentTestCase.java | 14 +-
.../AbstractArtifactComponentTestCase.java | 4 +-
.../project/AbstractMavenProjectTestCase.java | 17 +
.../project/EmptyLifecycleBindingsInjector.java | 163 ++
.../project/EmptyLifecyclePluginAnalyzer.java | 67 -
.../maven/project/ProjectClasspathTestType.java | 2 +-
.../apache/maven/project/TestProjectBuilder.java | 4 +-
.../AbstractProjectInheritanceTestCase.java | 9 +
.../inheritance/t02/ProjectInheritanceTest.java | 3 +
.../repository/LegacyRepositorySystemTest.java | 9 +-
.../META-INF/maven/org.apache.maven.api.di.Inject | 1 +
.../maven/project/AbstractMavenProjectTestCase.xml | 9 -
maven-core/pom.xml | 1 +
.../main/java/org/apache/maven/DefaultMaven.java | 2 +-
.../main/java/org/apache/maven/ReactorReader.java | 6 +-
.../metadata/io/DefaultMetadataReader.java | 1 +
.../execution/DefaultMavenExecutionRequest.java | 3 +-
.../DefaultRepositorySystemSessionFactory.java | 9 +-
.../LegacyRepositorySystemSessionExtender.java | 7 +-
.../internal/impl/DefaultLifecycleRegistry.java | 14 +-
.../internal/impl/DefaultPackagingRegistry.java | 38 +-
.../apache/maven/internal/impl/DefaultSession.java | 33 +-
.../maven/internal/impl/DefaultSessionFactory.java | 9 +-
.../apache/maven/internal/impl/EventSpyImpl.java | 3 +-
.../maven/internal/impl/SisuDiBridgeModule.java | 194 ++-
.../impl/DefaultConsumerPomBuilder.java | 167 +-
.../plugin/DefaultLifecycleBindingsInjector.java | 6 +-
.../DefaultPluginDependenciesResolver.java | 7 +-
.../project/DefaultModelBuildingListener.java | 49 +-
.../maven/project/DefaultProjectBuilder.java | 551 +++++--
.../DefaultProjectDependenciesResolver.java | 11 +-
.../org/apache/maven/project/ProjectBuilder.java | 13 +
.../apache/maven/project/ProjectModelResolver.java | 13 +-
.../org/apache/maven/project/ReactorModelPool.java | 2 +-
.../resolver/MavenChainedWorkspaceReader.java | 4 +-
.../maven/AbstractCoreMavenComponentTestCase.java | 16 +-
.../java/org/apache/maven/DefaultMavenTest.java | 6 +-
.../java/org/apache/maven/MavenTestHelper.java | 36 +
.../org/apache/maven/internal/impl/TestApi.java | 1 -
.../transformation/AbstractRepositoryTestCase.java | 18 +-
.../impl/ConsumerPomBuilderTest.java | 6 +
.../org/apache/maven/model/ModelBuilderTest.java | 22 +-
.../project/AbstractMavenProjectTestCase.java | 19 +
.../project/EmptyLifecycleBindingsInjector.java | 163 ++
.../apache/maven/project/PomConstructionTest.java | 4 +-
.../settings/PomConstructionWithSettingsTest.java | 3 +-
.../META-INF/maven/org.apache.maven.api.di.Inject | 1 +
.../org/apache/maven/di/impl/InjectorImpl.java | 52 +-
.../main/java/org/apache/maven/di/impl/Types.java | 20 +-
.../internal/BootstrapCoreExtensionManager.java | 65 +-
maven-model-builder/pom.xml | 4 +
.../model/building/DefaultModelProcessor.java | 3 +-
.../apache/maven/model/locator/ModelLocator.java | 5 +-
.../apache/maven/model/merge/MavenModelMerger.java | 594 +------
maven-model/pom.xml | 21 +-
maven-repository-metadata/pom.xml | 20 +-
.../metadata/io/xpp3/MetadataXpp3Reader.java | 2 +-
.../metadata/io/xpp3/MetadataXpp3Writer.java | 2 +-
.../artifact/repository/metadata/MetadataTest.java | 4 +-
.../internal/DefaultVersionRangeResolver.java | 2 +-
.../internal/DefaultVersionResolver.java | 2 +-
.../maven/repository/internal/MavenMetadata.java | 4 +-
.../maven/internal/xml/XmlNodeStaxBuilder.java | 7 +
205 files changed, 16921 insertions(+), 1664 deletions(-)
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Packaging.java b/api/maven-api-core/src/main/java/org/apache/maven/api/Packaging.java
index 37d3ed61c8..6f629c257c 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Packaging.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Packaging.java
@@ -18,6 +18,8 @@
*/
package org.apache.maven.api;
+import java.util.Map;
+
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
@@ -55,9 +57,9 @@ public interface Packaging extends ExtensibleEnum {
Type type();
/**
- * Returns the binding to use specifically for this packaging.
- * This will be merged to the default packaging definition.
+ * Returns the binding to use specifically for this packaging keyed by lifecycle id.
+ * This will be used instead of the default packaging definition.
*/
@Nonnull
- PluginContainer plugins();
+ Map<String, PluginContainer> plugins();
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilder.java
similarity index 58%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilder.java
index ca4c40d48a..aa828d349d 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilder.java
@@ -18,26 +18,18 @@
*/
package org.apache.maven.api.services;
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Nonnull;
+import java.util.List;
-/**
- * Access to {@link Type} registry.
- *
- * @since 4.0.0
- */
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
+import org.apache.maven.api.Service;
+import org.apache.maven.api.model.Model;
+
+public interface ModelBuilder extends Service {
+
+ List<String> VALID_MODEL_VERSIONS = List.of("4.0.0", "4.1.0");
+
+ ModelBuilderResult build(ModelBuilderRequest request) throws ModelBuilderException;
+
+ ModelTransformerContextBuilder newTransformerContextBuilder();
- /**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
- *
- * @param id the id of the type to retrieve
- * @return the type
- */
- @Nonnull
- Type require(@Nonnull String id);
+ Model buildRawModel(ModelBuilderRequest request);
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderException.java
new file mode 100644
index 0000000000..0448904665
--- /dev/null
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderException.java
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.api.annotations.Experimental;
+
+/**
+ * The Exception class throw by the {@link ProjectBuilder} service.
+ *
+ * @since 4.0.0
+ */
+@Experimental
+public class ModelBuilderException extends MavenException {
+
+ private final ModelBuilderResult result;
+
+ /**
+ * Creates a new exception from the specified interim result and its associated problems.
+ *
+ * @param result The interim result, may be {@code null}.
+ */
+ public ModelBuilderException(ModelBuilderResult result) {
+ super(result.toString());
+ this.result = result;
+ }
+
+ /**
+ * Gets the interim result of the model building up to the point where it failed.
+ *
+ * @return The interim model building result or {@code null} if not available.
+ */
+ public ModelBuilderResult getResult() {
+ return result;
+ }
+
+ /**
+ * Gets the identifier of the POM whose effective model could not be built. The general format of the identifier is
+ * {@code <groupId>:<artifactId>:<version>} but some of these coordinates may still be unknown at the point the
+ * exception is thrown so this information is merely meant to assist the user.
+ *
+ * @return The identifier of the POM or an empty string if not known, never {@code null}.
+ */
+ public String getModelId() {
+ if (result == null || result.getModelIds().isEmpty()) {
+ return "";
+ }
+ return result.getModelIds().get(0);
+ }
+
+ /**
+ * Gets the problems that caused this exception.
+ *
+ * @return The problems that caused this exception, never {@code null}.
+ */
+ public List<ModelProblem> getProblems() {
+ if (result == null) {
+ return Collections.emptyList();
+ }
+ return Collections.unmodifiableList(result.getProblems());
+ }
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java
new file mode 100644
index 0000000000..23ce6de182
--- /dev/null
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java
@@ -0,0 +1,454 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services;
+
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.api.Session;
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.annotations.Immutable;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.NotThreadSafe;
+import org.apache.maven.api.annotations.Nullable;
+import org.apache.maven.api.model.Profile;
+
+import static org.apache.maven.api.services.BaseRequest.nonNull;
+
+/**
+ * Request used to build a {@link org.apache.maven.api.Project} using
+ * the {@link ProjectBuilder} service.
+ *
+ * TODO: add validationLevel, activeProfileIds, inactiveProfileIds, resolveDependencies
+ *
+ * @since 4.0.0
+ */
+@Experimental
+@Immutable
+public interface ModelBuilderRequest {
+
+ /**
+ * Denotes minimal validation of POMs. This validation level is meant for processing of POMs from repositories
+ * during metadata retrieval.
+ */
+ int VALIDATION_LEVEL_MINIMAL = 0;
+
+ /**
+ * Denotes validation as performed by Maven 2.0. This validation level is meant as a compatibility mode to allow
+ * users to migrate their projects.
+ */
+ int VALIDATION_LEVEL_MAVEN_2_0 = 20;
+
+ /**
+ * Denotes validation as performed by Maven 3.0. This validation level is meant for existing projects.
+ */
+ int VALIDATION_LEVEL_MAVEN_3_0 = 30;
+
+ /**
+ * Denotes validation as performed by Maven 3.1. This validation level is meant for existing projects.
+ */
+ int VALIDATION_LEVEL_MAVEN_3_1 = 31;
+
+ /**
+ * Denotes validation as performed by Maven 4.0. This validation level is meant for new projects.
+ */
+ int VALIDATION_LEVEL_MAVEN_4_0 = 40;
+
+ /**
+ * Denotes strict validation as recommended by the current Maven version.
+ */
+ int VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_4_0;
+
+ @Nonnull
+ Session getSession();
+
+ @Nonnull
+ ModelSource getSource();
+
+ int getValidationLevel();
+
+ boolean isTwoPhaseBuilding();
+
+ boolean isLocationTracking();
+
+ /**
+ * Indicates if the model to be built is a local project or a dependency.
+ * In case the project is loaded externally from a remote repository (as a dependency or
+ * even as an external parent), the POM will be parsed in a lenient way. Local POMs
+ * are parsed more strictly.
+ */
+ boolean isProjectBuild();
+
+ /**
+ * Specifies whether plugin processing should take place for the built model.
+ * This involves merging plugins specified by the {@link org.apache.maven.api.Packaging},
+ * configuration expansion (merging configuration defined globally for a given plugin
+ * using {@link org.apache.maven.api.model.Plugin#getConfiguration()}
+ * into the configuration for each {@link org.apache.maven.api.model.PluginExecution}.
+ */
+ boolean isProcessPlugins();
+
+ /**
+ * Defines external profiles that may be activated for the given model.
+ * Those are external profiles usually defined in {@link org.apache.maven.api.settings.Settings#getProfiles()}.
+ */
+ @Nonnull
+ Collection<Profile> getProfiles();
+
+ /**
+ * List of profile ids that have been explicitly activated by the user.
+ */
+ @Nonnull
+ List<String> getActiveProfileIds();
+
+ /**
+ * List of profile ids that have been explicitly deactivated by the user.
+ */
+ @Nonnull
+ List<String> getInactiveProfileIds();
+
+ /**
+ * Provides a map of system properties.
+ */
+ @Nonnull
+ Map<String, String> getSystemProperties();
+
+ /**
+ * Provides a map of user properties.
+ * User properties
+ */
+ @Nonnull
+ Map<String, String> getUserProperties();
+
+ ModelResolver getModelResolver();
+
+ @Nullable
+ Object getListener();
+
+ @Nullable
+ ModelBuilderResult getInterimResult();
+
+ @Nullable
+ ModelTransformerContextBuilder getTransformerContextBuilder();
+
+ @Nonnull
+ static ModelBuilderRequest build(@Nonnull ModelBuilderRequest request, @Nonnull ModelSource source) {
+ return builder(nonNull(request, "request cannot be null"))
+ .source(nonNull(source, "source cannot be null"))
+ .build();
+ }
+
+ @Nonnull
+ static ModelBuilderRequest build(@Nonnull Session session, @Nonnull ModelSource source) {
+ return builder()
+ .session(nonNull(session, "session cannot be null"))
+ .source(nonNull(source, "source cannot be null"))
+ .build();
+ }
+
+ @Nonnull
+ static ModelBuilderRequest build(@Nonnull Session session, @Nonnull Path path) {
+ return builder()
+ .session(nonNull(session, "session cannot be null"))
+ .source(ModelSource.fromPath(path))
+ .build();
+ }
+
+ @Nonnull
+ static ModelBuilderRequestBuilder builder() {
+ return new ModelBuilderRequestBuilder();
+ }
+
+ @Nonnull
+ static ModelBuilderRequestBuilder builder(ModelBuilderRequest request) {
+ return new ModelBuilderRequestBuilder(request);
+ }
+
+ @NotThreadSafe
+ class ModelBuilderRequestBuilder {
+ Session session;
+ int validationLevel;
+ boolean locationTracking;
+ boolean twoPhaseBuilding;
+ ModelSource source;
+ boolean projectBuild;
+ boolean processPlugins = true;
+ Collection<Profile> profiles;
+ List<String> activeProfileIds;
+ List<String> inactiveProfileIds;
+ Map<String, String> systemProperties;
+ Map<String, String> userProperties;
+ ModelResolver modelResolver;
+ Object listener;
+ ModelBuilderResult interimResult;
+ ModelTransformerContextBuilder transformerContextBuilder;
+
+ ModelBuilderRequestBuilder() {}
+
+ ModelBuilderRequestBuilder(ModelBuilderRequest request) {
+ this.session = request.getSession();
+ this.validationLevel = request.getValidationLevel();
+ this.locationTracking = request.isLocationTracking();
+ this.twoPhaseBuilding = request.isTwoPhaseBuilding();
+ this.source = request.getSource();
+ this.projectBuild = request.isProjectBuild();
+ this.processPlugins = request.isProcessPlugins();
+ this.profiles = request.getProfiles();
+ this.activeProfileIds = request.getActiveProfileIds();
+ this.inactiveProfileIds = request.getInactiveProfileIds();
+ this.systemProperties = request.getSystemProperties();
+ this.userProperties = request.getUserProperties();
+ this.modelResolver = request.getModelResolver();
+ this.listener = request.getListener();
+ this.interimResult = request.getInterimResult();
+ this.transformerContextBuilder = request.getTransformerContextBuilder();
+ }
+
+ public ModelBuilderRequestBuilder session(Session session) {
+ this.session = session;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder validationLevel(int validationLevel) {
+ this.validationLevel = validationLevel;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder twoPhaseBuilding(boolean twoPhaseBuilding) {
+ this.twoPhaseBuilding = twoPhaseBuilding;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder locationTracking(boolean locationTracking) {
+ this.locationTracking = locationTracking;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder source(ModelSource source) {
+ this.source = source;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder projectBuild(boolean projectBuild) {
+ this.projectBuild = projectBuild;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder processPlugins(boolean processPlugins) {
+ this.processPlugins = processPlugins;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder profiles(List<Profile> profiles) {
+ this.profiles = profiles;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder activeProfileIds(List<String> activeProfileIds) {
+ this.activeProfileIds = activeProfileIds;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder inactiveProfileIds(List<String> inactiveProfileIds) {
+ this.inactiveProfileIds = inactiveProfileIds;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder systemProperties(Map<String, String> systemProperties) {
+ this.systemProperties = systemProperties;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder userProperties(Map<String, String> userProperties) {
+ this.userProperties = userProperties;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder modelResolver(ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder listener(Object listener) {
+ this.listener = listener;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder interimResult(ModelBuilderResult interimResult) {
+ this.interimResult = interimResult;
+ return this;
+ }
+
+ public ModelBuilderRequestBuilder transformerContextBuilder(
+ ModelTransformerContextBuilder transformerContextBuilder) {
+ this.transformerContextBuilder = transformerContextBuilder;
+ return this;
+ }
+
+ public ModelBuilderRequest build() {
+ return new DefaultModelBuilderRequest(
+ session,
+ validationLevel,
+ locationTracking,
+ twoPhaseBuilding,
+ source,
+ projectBuild,
+ processPlugins,
+ profiles,
+ activeProfileIds,
+ inactiveProfileIds,
+ systemProperties,
+ userProperties,
+ modelResolver,
+ listener,
+ interimResult,
+ transformerContextBuilder);
+ }
+
+ private static class DefaultModelBuilderRequest extends BaseRequest implements ModelBuilderRequest {
+ private final int validationLevel;
+ private final boolean locationTracking;
+ private final boolean twoPhaseBuilding;
+ private final ModelSource source;
+ private final boolean projectBuild;
+ private final boolean processPlugins;
+ private final Collection<Profile> profiles;
+ private final List<String> activeProfileIds;
+ private final List<String> inactiveProfileIds;
+ private final Map<String, String> systemProperties;
+ private final Map<String, String> userProperties;
+ private final ModelResolver modelResolver;
+ private final Object listener;
+ private final ModelBuilderResult interimResult;
+ private final ModelTransformerContextBuilder transformerContextBuilder;
+
+ @SuppressWarnings("checkstyle:ParameterNumber")
+ DefaultModelBuilderRequest(
+ @Nonnull Session session,
+ int validationLevel,
+ boolean locationTracking,
+ boolean twoPhaseBuilding,
+ @Nonnull ModelSource source,
+ boolean projectBuild,
+ boolean processPlugins,
+ Collection<Profile> profiles,
+ List<String> activeProfileIds,
+ List<String> inactiveProfileIds,
+ Map<String, String> systemProperties,
+ Map<String, String> userProperties,
+ ModelResolver modelResolver,
+ Object listener,
+ ModelBuilderResult interimResult,
+ ModelTransformerContextBuilder transformerContextBuilder) {
+ super(session);
+ this.validationLevel = validationLevel;
+ this.locationTracking = locationTracking;
+ this.twoPhaseBuilding = twoPhaseBuilding;
+ this.source = source;
+ this.projectBuild = projectBuild;
+ this.processPlugins = processPlugins;
+ this.profiles = profiles != null ? List.copyOf(profiles) : List.of();
+ this.activeProfileIds = activeProfileIds != null ? List.copyOf(activeProfileIds) : List.of();
+ this.inactiveProfileIds = inactiveProfileIds != null ? List.copyOf(inactiveProfileIds) : List.of();
+ this.systemProperties =
+ systemProperties != null ? Map.copyOf(systemProperties) : session.getSystemProperties();
+ this.userProperties = userProperties != null ? Map.copyOf(userProperties) : session.getUserProperties();
+ this.modelResolver = modelResolver;
+ this.listener = listener;
+ this.interimResult = interimResult;
+ this.transformerContextBuilder = transformerContextBuilder;
+ }
+
+ @Override
+ public int getValidationLevel() {
+ return validationLevel;
+ }
+
+ @Override
+ public boolean isTwoPhaseBuilding() {
+ return twoPhaseBuilding;
+ }
+
+ @Override
+ public boolean isLocationTracking() {
+ return locationTracking;
+ }
+
+ @Nonnull
+ @Override
+ public ModelSource getSource() {
+ return source;
+ }
+
+ public boolean isProjectBuild() {
+ return projectBuild;
+ }
+
+ @Override
+ public boolean isProcessPlugins() {
+ return processPlugins;
+ }
+
+ @Override
+ public Collection<Profile> getProfiles() {
+ return profiles;
+ }
+
+ @Override
+ public List<String> getActiveProfileIds() {
+ return activeProfileIds;
+ }
+
+ @Override
+ public List<String> getInactiveProfileIds() {
+ return inactiveProfileIds;
+ }
+
+ @Override
+ public Map<String, String> getSystemProperties() {
+ return systemProperties;
+ }
+
+ @Override
+ public Map<String, String> getUserProperties() {
+ return userProperties;
+ }
+
+ @Override
+ public ModelResolver getModelResolver() {
+ return modelResolver;
+ }
+
+ public Object getListener() {
+ return listener;
+ }
+
+ @Override
+ public ModelBuilderResult getInterimResult() {
+ return interimResult;
+ }
+
+ public ModelTransformerContextBuilder getTransformerContextBuilder() {
+ return transformerContextBuilder;
+ }
+ }
+ }
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderResult.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderResult.java
new file mode 100644
index 0000000000..9c7829295e
--- /dev/null
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderResult.java
@@ -0,0 +1,125 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Profile;
+
+/**
+ * Result of a project build call.
+ *
+ * @since 4.0.0
+ */
+@Experimental
+public interface ModelBuilderResult {
+
+ /**
+ * Gets the sequence of model identifiers that denote the lineage of models from which the effective model was
+ * constructed. Model identifiers have the form {@code <groupId>:<artifactId>:<version>}. The first identifier from
+ * the list denotes the model on which the model builder was originally invoked. The last identifier will always be
+ * an empty string that by definition denotes the super POM.
+ *
+ * @return The model identifiers from the lineage of models, never {@code null}.
+ */
+ @Nonnull
+ List<String> getModelIds();
+
+ /**
+ * Gets the file model.
+ *
+ * @return the file model, never {@code null}.
+ */
+ @Nonnull
+ Model getFileModel();
+
+ /**
+ * Returns the file model + profile injection.
+ *
+ * @return the activated file model, never {@code null}.
+ */
+ @Nonnull
+ Model getActivatedFileModel();
+
+ /**
+ * Gets the file model + build pom transformation, without inheritance nor interpolation.
+ *
+ * @return The raw model, never {@code null}.
+ */
+ @Nonnull
+ Model getRawModel();
+
+ /**
+ * Gets the assembled model with inheritance, interpolation and profile injection.
+ *
+ * @return The assembled model, never {@code null}.
+ */
+ @Nonnull
+ Model getEffectiveModel();
+
+ /**
+ * Gets the specified raw model as it was read from a model source. Apart from basic validation, a raw model has not
+ * undergone any updates by the model builder, e.g. reflects neither inheritance nor interpolation. The model
+ * identifier should be from the collection obtained by {@link #getModelIds()}. As a special case, an empty string
+ * can be used as the identifier for the super POM.
+ *
+ * @param modelId The identifier of the desired raw model, must not be {@code null}.
+ * @return The raw model or {@code null} if the specified model id does not refer to a known model.
+ */
+ @Nonnull
+ Optional<Model> getRawModel(@Nonnull String modelId);
+
+ /**
+ * Gets the profiles from the specified model that were active during model building. The model identifier should be
+ * from the collection obtained by {@link #getModelIds()}. As a special case, an empty string can be used as the
+ * identifier for the super POM.
+ *
+ * @param modelId The identifier of the model whose active profiles should be retrieved, must not be {@code null}.
+ * @return The active profiles of the model or an empty list if the specified model id does
+ * not refer to a known model or has no active profiles.
+ */
+ @Nonnull
+ List<Profile> getActivePomProfiles(@Nonnull String modelId);
+
+ /**
+ * Gets the external profiles that were active during model building. External profiles are those that were
+ * contributed by {@link ModelBuilderRequest#getProfiles()}.
+ *
+ * @return The active external profiles or an empty list if none, never {@code null}.
+ */
+ @Nonnull
+ List<Profile> getActiveExternalProfiles();
+
+ /**
+ * Gets the problems that were encountered during the project building.
+ *
+ * @return the problems that were encountered during the project building, can be empty but never {@code null}
+ */
+ @Nonnull
+ List<ModelProblem> getProblems();
+
+ /**
+ * Creates a human readable representation of these errors.
+ */
+ String toString();
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelProblem.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelProblem.java
new file mode 100644
index 0000000000..0e20dbee98
--- /dev/null
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelProblem.java
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services;
+
+/**
+ * Describes a problem that was encountered during model building. A problem can either be an exception that was thrown
+ * or a simple string message. In addition, a problem carries a hint about its source, e.g. the POM file that exhibits
+ * the problem.
+ *
+ */
+public interface ModelProblem extends BuilderProblem {
+
+ /**
+ * Version
+ */
+ enum Version {
+ // based on ModeBuildingResult.validationLevel
+ BASE,
+ V20,
+ V30,
+ V31,
+ V40
+ }
+
+ /**
+ * Gets the identifier of the model from which the problem originated. While the general form of this identifier is
+ * <code>groupId:artifactId:version</code> the returned identifier need not be complete. The identifier is derived
+ * from the information that is available at the point the problem occurs and as such merely serves as a best effort
+ * to provide information to the user to track the problem back to its origin.
+ *
+ * @return The identifier of the model from which the problem originated or an empty string if unknown, never
+ * {@code null}.
+ */
+ String getModelId();
+
+ /**
+ * Gets the applicable maven version/validation level of this problem
+ * @return The version, never {@code null}.
+ */
+ Version getVersion();
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelProblemCollector.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelProblemCollector.java
new file mode 100644
index 0000000000..06d68b09d2
--- /dev/null
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelProblemCollector.java
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services;
+
+import java.util.List;
+
+import org.apache.maven.api.model.InputLocation;
+
+/**
+ * Collects problems that are encountered during model building. The primary purpose of this component is to account for
+ * the fact that the problem reporter has/should not have information about the calling context and hence cannot provide
+ * an expressive source hint for the model problem. Instead, the source hint is configured by the model builder before
+ * it delegates to other components that potentially encounter problems. Then, the problem reporter can focus on
+ * providing a simple error message, leaving the donkey work of creating a nice model problem to this component.
+ *
+ */
+public interface ModelProblemCollector {
+
+ /**
+ * The collected problems.
+ * @return a list of model problems encountered, never {@code null}
+ */
+ List<ModelProblem> getProblems();
+
+ boolean hasErrors();
+
+ boolean hasFatalErrors();
+
+ default void add(BuilderProblem.Severity severity, ModelProblem.Version version, String message) {
+ add(severity, version, message, null, null);
+ }
+
+ default void add(
+ BuilderProblem.Severity severity, ModelProblem.Version version, String message, InputLocation location) {
+ add(severity, version, message, location, null);
+ }
+
+ default void add(
+ BuilderProblem.Severity severity, ModelProblem.Version version, String message, Exception exception) {
+ add(severity, version, message, null, exception);
+ }
+
+ void add(
+ BuilderProblem.Severity severity,
+ ModelProblem.Version version,
+ String message,
+ InputLocation location,
+ Exception exception);
+
+ void add(ModelProblem problem);
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelResolver.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelResolver.java
new file mode 100644
index 0000000000..72a114a80e
--- /dev/null
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelResolver.java
@@ -0,0 +1,125 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.maven.api.Service;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.model.Dependency;
+import org.apache.maven.api.model.Parent;
+import org.apache.maven.api.model.Repository;
+
+/**
+ * Resolves a POM from its coordinates. During the build process, the
+ * {@link org.apache.maven.api.services.ModelBuilder} will add any relevant repositories to the model resolver. In
+ * other words, the model resolver is stateful and should not be reused across multiple model building requests.
+ *
+ */
+public interface ModelResolver extends Service {
+
+ /**
+ * Tries to resolve the POM for the specified coordinates.
+ *
+ * @param groupId The group identifier of the POM, must not be {@code null}.
+ * @param artifactId The artifact identifier of the POM, must not be {@code null}.
+ * @param version The version of the POM, must not be {@code null}.
+ * @return The source of the requested POM, never {@code null}.
+ * @throws ModelResolverException If the POM could not be resolved from any configured repository.
+ */
+ @Nonnull
+ ModelSource resolveModel(
+ @Nonnull Session session, @Nonnull String groupId, @Nonnull String artifactId, @Nonnull String version)
+ throws ModelResolverException;
+
+ /**
+ * Tries to resolve the POM for the specified parent coordinates possibly updating {@code parent}.
+ * <p>
+ * Unlike the {@link #resolveModel(Session, String, String, String)} method, this method
+ * supports version ranges and updates the given {@code parent} instance to match the returned {@code ModelSource}.
+ * If {@code parent} declares a version range, the version corresponding to the returned {@code ModelSource} will
+ * be set on the given {@code parent}.
+ * </p>
+ *
+ * @param parent The parent coordinates to resolve, must not be {@code null}.
+ *
+ * @return The source of the requested POM, never {@code null}.
+ *
+ * @throws ModelResolverException If the POM could not be resolved from any configured repository.
+ */
+ @Nonnull
+ ModelSource resolveModel(
+ @Nonnull Session session, @Nonnull Parent parent, @Nonnull AtomicReference<Parent> modified)
+ throws ModelResolverException;
+
+ /**
+ * Tries to resolve the POM for the specified dependency coordinates possibly updating {@code dependency}.
+ * <p>
+ * Unlike the {@link #resolveModel(Session, String, String, String)} method, this method
+ * supports version ranges and updates the given {@code dependency} instance to match the returned
+ * {@code ModelSource}. If {@code dependency} declares a version range, the version corresponding to the returned
+ * {@code ModelSource} will be set on the given {@code dependency}.
+ * </p>
+ *
+ * @param dependency The dependency coordinates to resolve, must not be {@code null}.
+ *
+ * @return The source of the requested POM, never {@code null}.
+ *
+ * @throws ModelResolverException If the POM could not be resolved from any configured repository.
+ *
+ * @see Dependency#clone()
+ */
+ @Nonnull
+ ModelSource resolveModel(
+ @Nonnull Session session, @Nonnull Dependency dependency, @Nonnull AtomicReference<Dependency> modified)
+ throws ModelResolverException;
+
+ /**
+ * Adds a repository to use for subsequent resolution requests. The order in which repositories are added matters,
+ * repositories that were added first should also be searched first. When multiple repositories with the same
+ * identifier are added, only the first repository being added will be used.
+ *
+ * @param repository The repository to add to the internal search chain, must not be {@code null}.
+ * @throws ModelResolverException If the repository could not be added (e.g. due to invalid URL or layout).
+ */
+ void addRepository(@Nonnull Session session, Repository repository) throws ModelResolverException;
+
+ /**
+ * Adds a repository to use for subsequent resolution requests. The order in which repositories are added matters,
+ * repositories that were added first should also be searched first. When multiple repositories with the same
+ * identifier are added, then the value of the replace argument determines the behaviour.
+ *
+ * If replace is false then any existing repository with the same Id will remain in use. If replace
+ * is true the new repository replaces the original.
+ *
+ * @param repository The repository to add to the internal search chain, must not be {@code null}.
+ * @throws ModelResolverException If the repository could not be added (e.g. due to invalid URL or layout).
+ */
+ void addRepository(@Nonnull Session session, Repository repository, boolean replace) throws ModelResolverException;
+
+ /**
+ * Clones this resolver for usage in a forked resolution process. In general, implementors need not provide a deep
+ * clone. The only requirement is that invocations of {@link #addRepository(Session, Repository)} on the clone do not affect
+ * the state of the original resolver and vice versa.
+ *
+ * @return The cloned resolver, never {@code null}.
+ */
+ ModelResolver newCopy();
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelResolverException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelResolverException.java
new file mode 100644
index 0000000000..167e67070a
--- /dev/null
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelResolverException.java
@@ -0,0 +1,114 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services;
+
+/**
+ * Signals an error when resolving the path to an external model.
+ *
+ */
+public class ModelResolverException extends MavenException {
+
+ /**
+ * The group id of the unresolvable model.
+ */
+ private final String groupId;
+
+ /**
+ * The artifact id of the unresolvable model.
+ */
+ private final String artifactId;
+
+ /**
+ * The version of the unresolvable model.
+ */
+ private final String version;
+
+ /**
+ * Creates a new exception with specified detail message and cause.
+ *
+ * @param message The detail message, may be {@code null}.
+ * @param groupId The group id of the unresolvable model, may be {@code null}.
+ * @param artifactId The artifact id of the unresolvable model, may be {@code null}.
+ * @param version The version of the unresolvable model, may be {@code null}.
+ * @param cause The cause, may be {@code null}.
+ */
+ public ModelResolverException(String message, String groupId, String artifactId, String version, Throwable cause) {
+ super(message, cause);
+ this.groupId = (groupId != null) ? groupId : "";
+ this.artifactId = (artifactId != null) ? artifactId : "";
+ this.version = (version != null) ? version : "";
+ }
+
+ /**
+ * Creates a new exception with specified detail message.
+ *
+ * @param message The detail message, may be {@code null}.
+ * @param groupId The group id of the unresolvable model, may be {@code null}.
+ * @param artifactId The artifact id of the unresolvable model, may be {@code null}.
+ * @param version The version of the unresolvable model, may be {@code null}.
+ */
+ public ModelResolverException(String message, String groupId, String artifactId, String version) {
+ super(message);
+ this.groupId = (groupId != null) ? groupId : "";
+ this.artifactId = (artifactId != null) ? artifactId : "";
+ this.version = (version != null) ? version : "";
+ }
+
+ /**
+ * Creates a new exception with specified cause
+ *
+ * @param cause
+ * @param groupId
+ * @param artifactId
+ * @param version
+ */
+ public ModelResolverException(Throwable cause, String groupId, String artifactId, String version) {
+ super(cause);
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ }
+
+ /**
+ * Gets the group id of the unresolvable model.
+ *
+ * @return The group id of the unresolvable model, can be empty but never {@code null}.
+ */
+ public String getGroupId() {
+ return groupId;
+ }
+
+ /**
+ * Gets the artifact id of the unresolvable model.
+ *
+ * @return The artifact id of the unresolvable model, can be empty but never {@code null}.
+ */
+ public String getArtifactId() {
+ return artifactId;
+ }
+
+ /**
+ * Gets the version of the unresolvable model.
+ *
+ * @return The version of the unresolvable model, can be empty but never {@code null}.
+ */
+ public String getVersion() {
+ return version;
+ }
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelSource.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelSource.java
new file mode 100644
index 0000000000..2082cf2db8
--- /dev/null
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelSource.java
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services;
+
+import java.nio.file.Path;
+
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.Nullable;
+
+import static org.apache.maven.api.services.BaseRequest.nonNull;
+
+/**
+ * A Source specific to load POMs. The {@link #resolve(ModelLocator, String)} method
+ * will be used to find POMs for children modules.
+ *
+ * @since 4.0.0
+ */
+public interface ModelSource extends Source {
+
+ interface ModelLocator {
+ /**
+ * Returns the file containing the pom or null if a pom can not be
+ * found at the given file or in the given directory.
+ *
+ * @since 4.0.0
+ */
+ @Nullable
+ Path locateExistingPom(@Nonnull Path project);
+ }
+
+ @Nullable
+ ModelSource resolve(@Nonnull ModelLocator modelLocator, @Nonnull String relative);
+
+ @Nonnull
+ static ModelSource fromPath(@Nonnull Path path) {
+ return fromPath(path, null);
+ }
+
+ @Nonnull
+ static ModelSource fromPath(@Nonnull Path path, @Nullable String location) {
+ return new PathSource(nonNull(path, "path cannot be null"), location);
+ }
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformer.java
similarity index 57%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformer.java
index ca4c40d48a..0c17ae41bc 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformer.java
@@ -18,26 +18,27 @@
*/
package org.apache.maven.api.services;
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
+import java.nio.file.Path;
+
import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.model.Model;
/**
- * Access to {@link Type} registry.
+ * The ModelTransformer is a way to transform the local pom while streaming the input.
+ *
+ * The {@link #transform(ModelTransformerContext, Model, Path)} method uses a Path on purpose, to ensure the
+ * local pom is the original source.
*
* @since 4.0.0
*/
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
-
+public interface ModelTransformer {
/**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
- *
- * @param id the id of the type to retrieve
- * @return the type
+ * @param context the context, cannot be null
+ * @param model the model to transform
+ * @param path the pom file, cannot be null
+ * @throws ModelTransformerException if the transformation fails
*/
@Nonnull
- Type require(@Nonnull String id);
+ Model transform(@Nonnull ModelTransformerContext context, @Nonnull Model model, @Nonnull Path path)
+ throws ModelTransformerException;
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformerContext.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformerContext.java
new file mode 100644
index 0000000000..a6e31720fa
--- /dev/null
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformerContext.java
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services;
+
+import java.nio.file.Path;
+
+import org.apache.maven.api.model.Model;
+
+/**
+ * Context used to transform a pom file.
+ *
+ * @since 4.0.0
+ */
+public interface ModelTransformerContext {
+
+ /**
+ * Key to get the TransformerContext from the SessionData
+ */
+ Object KEY = ModelTransformerContext.class;
+
+ /**
+ * Get the value of the Maven user property.
+ */
+ String getUserProperty(String key);
+
+ /**
+ * Get the model based on the path when resolving the parent based on relativePath.
+ *
+ * @param from the requiring model
+ * @param pomFile the path to the pomFile
+ * @return the model, otherwise {@code null}
+ */
+ Model getRawModel(Path from, Path pomFile);
+
+ /**
+ * Get the model from the reactor based on the groupId and artifactId when resolving reactor dependencies.
+ *
+ * @param from the requiring model
+ * @param groupId the groupId
+ * @param artifactId the artifactId
+ * @return the model, otherwise {@code null}
+ * @throws IllegalStateException if multiple versions of the same GA are part of the reactor
+ */
+ Model getRawModel(Path from, String groupId, String artifactId);
+
+ /**
+ * Locate the POM file inside the given directory.
+ */
+ Path locate(Path path);
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformerContextBuilder.java
similarity index 55%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformerContextBuilder.java
index ca4c40d48a..9efb6e63ee 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformerContextBuilder.java
@@ -18,26 +18,26 @@
*/
package org.apache.maven.api.services;
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Nonnull;
-
/**
- * Access to {@link Type} registry.
+ * The transformerContextBuilder is responsible for initializing the TransformerContext.
+ * In case rawModels are missing, it could do new buildingRequests on the ModelBuilder.
*
* @since 4.0.0
*/
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
+public interface ModelTransformerContextBuilder {
+ /**
+ * This method is used to initialize the TransformerContext
+ *
+ * @param request the modelBuildingRequest
+ * @param problems the problemCollector
+ * @return the mutable transformerContext
+ */
+ ModelTransformerContext initialize(ModelBuilderRequest request, ModelProblemCollector problems);
/**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
+ * The immutable transformerContext, can be used after the buildplan is finished.
*
- * @param id the id of the type to retrieve
- * @return the type
+ * @return the immutable transformerContext
*/
- @Nonnull
- Type require(@Nonnull String id);
+ ModelTransformerContext build();
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformerException.java
similarity index 60%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformerException.java
index ca4c40d48a..bf866c29a9 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelTransformerException.java
@@ -18,26 +18,17 @@
*/
package org.apache.maven.api.services;
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Nonnull;
-
/**
- * Access to {@link Type} registry.
*
* @since 4.0.0
*/
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
+public class ModelTransformerException extends MavenException {
+
+ public ModelTransformerException(Exception e) {
+ super(e);
+ }
- /**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
- *
- * @param id the id of the type to retrieve
- * @return the type
- */
- @Nonnull
- Type require(@Nonnull String id);
+ public ModelTransformerException(String message, Throwable exception) {
+ super(message, exception);
+ }
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java
index a114594947..9b3ce52220 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java
@@ -18,17 +18,25 @@
*/
package org.apache.maven.api.services;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.Objects;
-class PathSource implements Source {
+class PathSource implements ModelSource {
private final Path path;
+ private final String location;
PathSource(Path path) {
+ this(path, null);
+ }
+
+ PathSource(Path path, String location) {
this.path = path;
+ this.location = location != null ? location : path.toString();
}
@Override
@@ -43,11 +51,32 @@ class PathSource implements Source {
@Override
public String getLocation() {
- return path.toString();
+ return location;
}
@Override
public Source resolve(String relative) {
return new PathSource(path.resolve(relative));
}
+
+ @Override
+ public ModelSource resolve(ModelLocator locator, String relative) {
+ String norm = relative.replace('\\', File.separatorChar).replace('/', File.separatorChar);
+ Path path = getPath().getParent().resolve(norm);
+ Path relatedPom = locator.locateExistingPom(path);
+ if (relatedPom != null) {
+ return new PathSource(relatedPom.normalize(), null);
+ }
+ return null;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return this == o || o instanceof PathSource ps && Objects.equals(path, ps.path);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(path);
+ }
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java
index 201c49e5f0..b882f724e3 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java
@@ -87,7 +87,8 @@ public interface Source {
* @param relative is the path of the requested source relative to this source
* @return related source or <code>null</code> if no such source
*/
- Source resolve(String relative);
+ @Nullable
+ Source resolve(@Nonnull String relative);
/**
* Creates a Source for the following Path
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
index ca4c40d48a..8c2c872a17 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
@@ -39,5 +39,8 @@ public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
* @return the type
*/
@Nonnull
- Type require(@Nonnull String id);
+ @Override
+ default Type require(@Nonnull String id) {
+ return lookup(id).orElseThrow(() -> new IllegalArgumentException("Unknown extensible enum value '" + id + "'"));
+ }
}
diff --git a/api/maven-api-metadata/pom.xml b/api/maven-api-metadata/pom.xml
index 1488f69222..ba4a488b4a 100644
--- a/api/maven-api-metadata/pom.xml
+++ b/api/maven-api-metadata/pom.xml
@@ -33,7 +33,7 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-xml-impl</artifactId>
+ <artifactId>maven-api-xml</artifactId>
</dependency>
</dependencies>
diff --git a/api/maven-api-spi/src/main/java/org/apache/maven/api/spi/ModelParser.java b/api/maven-api-spi/src/main/java/org/apache/maven/api/spi/ModelParser.java
index c9e2efc486..bd1025d1ae 100644
--- a/api/maven-api-spi/src/main/java/org/apache/maven/api/spi/ModelParser.java
+++ b/api/maven-api-spi/src/main/java/org/apache/maven/api/spi/ModelParser.java
@@ -39,6 +39,11 @@ import org.apache.maven.api.services.Source;
@Consumer
public interface ModelParser extends SpiService {
+ /**
+ * Option that can be specified in the options map. The value should be a Boolean.
+ */
+ String STRICT = "strict";
+
/**
* Locates the pom in the given directory.
*
diff --git a/maven-api-impl/pom.xml b/maven-api-impl/pom.xml
index 2b3e560a71..9431ebad27 100644
--- a/maven-api-impl/pom.xml
+++ b/maven-api-impl/pom.xml
@@ -34,6 +34,14 @@ under the License.
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-api-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-api-metadata</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-di</artifactId>
@@ -52,7 +60,15 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-resolver-provider</artifactId>
+ <artifactId>maven-xml-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.resolver</groupId>
+ <artifactId>maven-resolver-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interpolation</artifactId>
</dependency>
<dependency>
@@ -60,6 +76,21 @@ under the License.
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.resolver</groupId>
+ <artifactId>maven-resolver-connector-basic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.resolver</groupId>
+ <artifactId>maven-resolver-transport-file</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.resolver</groupId>
+ <artifactId>maven-resolver-transport-apache</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -123,6 +154,59 @@ under the License.
</params>
</configuration>
</execution>
+ <execution>
+ <id>velocity-metadata</id>
+ <goals>
+ <goal>velocity</goal>
+ </goals>
+ <phase>generate-sources</phase>
+ <configuration>
+ <version>1.1.0</version>
+ <basedir>${project.basedir}/../api/maven-api-metadata</basedir>
+ <velocityBasedir>${project.basedir}/../src/mdo</velocityBasedir>
+ <models>
+ <model>src/main/mdo/metadata.mdo</model>
+ </models>
+ <templates>
+ <template>reader-stax.vm</template>
+ <template>writer-stax.vm</template>
+ </templates>
+ <params>
+ <param>packageModelV4=org.apache.maven.api.metadata</param>
+ <param>packageToolV4=org.apache.maven.metadata.v4</param>
+ </params>
+ </configuration>
+ </execution>
+ <execution>
+ <id>model-v4</id>
+ <goals>
+ <goal>velocity</goal>
+ </goals>
+ <phase>generate-sources</phase>
+ <configuration>
+ <version>4.1.0</version>
+ <basedir>${project.basedir}/../api/maven-api-model</basedir>
+ <velocityBasedir>${project.basedir}/../src/mdo</velocityBasedir>
+ <models>
+ <model>src/main/mdo/maven.mdo</model>
+ </models>
+ <templates>
+ <template>merger.vm</template>
+ <template>transformer.vm</template>
+ <template>reader-stax.vm</template>
+ <template>writer-stax.vm</template>
+ <template>model-version.vm</template>
+ </templates>
+ <params>
+ <param>forcedIOModelVersion=4.0.0</param>
+ <param>packageModelV3=org.apache.maven.model</param>
+ <param>packageModelV4=org.apache.maven.api.model</param>
+ <param>packageToolV4=org.apache.maven.model.v4</param>
+ <param>isMavenModel=true</param>
+ <param>minimalVersion=4.0.0</param>
+ </params>
+ </configuration>
+ </execution>
<execution>
<id>modello-site-docs</id>
<phase>none</phase>
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/DependencyManagementImporter.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/DependencyManagementImporter.java
new file mode 100644
index 0000000000..e48079b268
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/DependencyManagementImporter.java
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import java.util.List;
+
+import org.apache.maven.api.model.DependencyManagement;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Handles the import of dependency management from other models into the target model.
+ *
+ */
+public interface DependencyManagementImporter {
+
+ /**
+ * Imports the specified dependency management sections into the given target model.
+ *
+ * @param target The model into which to import the dependency management section, must not be <code>null</code>.
+ * @param sources The dependency management sections to import, may be <code>null</code>.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ Model importManagement(
+ Model target,
+ List<? extends DependencyManagement> sources,
+ ModelBuilderRequest request,
+ ModelProblemCollector problems);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/DependencyManagementInjector.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/DependencyManagementInjector.java
new file mode 100644
index 0000000000..129eaaa53e
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/DependencyManagementInjector.java
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Handles injection of dependency management into the model.
+ *
+ */
+public interface DependencyManagementInjector {
+
+ /**
+ * Merges default values from the dependency management section of the given model into itself.
+ *
+ * @param model The model into which to merge the values specified by its dependency management sections, must not
+ * be <code>null</code>.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ Model injectManagement(Model model, ModelBuilderRequest request, ModelProblemCollector problems);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/InheritanceAssembler.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/InheritanceAssembler.java
new file mode 100644
index 0000000000..4b1632809f
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/InheritanceAssembler.java
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Handles inheritance of model values.
+ *
+ */
+public interface InheritanceAssembler {
+
+ /**
+ * Merges values from the specified parent model into the given child model. Implementations are expected to keep
+ * parent and child completely decoupled by injecting deep copies of objects into the child rather than the original
+ * objects from the parent.
+ *
+ * @param child The child model into which to merge the values inherited from the parent, must not be
+ * <code>null</code>.
+ * @param parent The (read-only) parent model from which to inherit the values, may be <code>null</code>.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ Model assembleModelInheritance(
+ Model child, Model parent, ModelBuilderRequest request, ModelProblemCollector problems);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/LifecycleBindingsInjector.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/LifecycleBindingsInjector.java
new file mode 100644
index 0000000000..beba17ad3b
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/LifecycleBindingsInjector.java
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Handles injection of plugin executions induced by the lifecycle bindings for a packaging.
+ *
+ */
+public interface LifecycleBindingsInjector {
+
+ /**
+ * Injects plugin executions induced by lifecycle bindings into the specified model. The model has already undergone
+ * injection of plugin management so any plugins that are injected by lifecycle bindings and are not already present
+ * in the model's plugin section need to be subjected to the model's plugin management.
+ *
+ * @param model The model into which to inject the default plugin executions for its packaging, must not be
+ * <code>null</code>.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ Model injectLifecycleBindings(Model model, ModelBuilderRequest request, ModelProblemCollector problems);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelBuildingEvent.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelBuildingEvent.java
new file mode 100644
index 0000000000..f2d8bf8619
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelBuildingEvent.java
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import java.util.function.Consumer;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Holds data relevant for a model building event.
+ *
+ */
+public interface ModelBuildingEvent {
+
+ /**
+ * Gets the model being built. The precise state of this model depends on the event being fired.
+ *
+ * @return The model being built, never {@code null}.
+ */
+ Model model();
+
+ Consumer<Model> update();
+
+ /**
+ * Gets the model building request being processed.
+ *
+ * @return The model building request being processed, never {@code null}.
+ */
+ ModelBuilderRequest request();
+
+ /**
+ * Gets the container used to collect problems that were encountered while processing the event.
+ *
+ * @return The container used to collect problems that were encountered, never {@code null}.
+ */
+ ModelProblemCollector problems();
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelBuildingListener.java
similarity index 58%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelBuildingListener.java
index ca4c40d48a..a0c2bfb4a7 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelBuildingListener.java
@@ -16,28 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api.services;
-
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Nonnull;
+package org.apache.maven.api.services.model;
/**
- * Access to {@link Type} registry.
- *
- * @since 4.0.0
+ * Defines events that the model builder fires during construction of the effective model. When a listener encounters
+ * errors while processing the event, it can report these problems via {@link ModelBuildingEvent#problems()}.
*/
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
+public interface ModelBuildingListener {
/**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
+ * Notifies the listener that the model has been constructed to the extent where build extensions can be processed.
*
- * @param id the id of the type to retrieve
- * @return the type
+ * @param event The details about the event.
*/
- @Nonnull
- Type require(@Nonnull String id);
+ default void buildExtensionsAssembled(ModelBuildingEvent event) {}
}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelCache.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelCache.java
new file mode 100644
index 0000000000..39b4179c09
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelCache.java
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import java.util.function.Supplier;
+
+import org.apache.maven.api.services.Source;
+
+/**
+ * Caches auxiliary data used during model building like already processed raw/effective models. The data in the cache
+ * is meant for exclusive consumption by the model builder and is opaque to the cache implementation. The cache key is
+ * formed by a combination of group id, artifact id, version and tag. The first three components generally refer to the
+ * identity of a model. The tag allows for further classification of the associated data on the sole discretion of the
+ * model builder.
+ *
+ */
+public interface ModelCache {
+
+ <T> T computeIfAbsent(String groupId, String artifactId, String version, String tag, Supplier<T> data);
+
+ <T> T computeIfAbsent(Source path, String tag, Supplier<T> data);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelInterpolator.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelInterpolator.java
new file mode 100644
index 0000000000..ed3664c533
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelInterpolator.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import java.nio.file.Path;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Replaces expressions of the form <code>${token}</code> with their effective values. Effective values are basically
+ * calculated from the elements of the model itself and the execution properties from the building request.
+ *
+ */
+public interface ModelInterpolator {
+
+ /**
+ * Interpolates expressions in the specified model. Note that implementations are free to either interpolate the
+ * provided model directly or to create a clone of the model and interpolate the clone. Callers should always use
+ * the returned model and must not rely on the input model being updated.
+ *
+ * @param model The model to interpolate, must not be {@code null}.
+ * @param projectDir The project directory, may be {@code null} if the model does not belong to a local project but
+ * to some artifact's metadata.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ * @return The interpolated model, never {@code null}.
+ * @since 4.0.0
+ */
+ Model interpolateModel(Model model, Path projectDir, ModelBuilderRequest request, ModelProblemCollector problems);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelNormalizer.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelNormalizer.java
new file mode 100644
index 0000000000..40891f041c
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelNormalizer.java
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Handles normalization of a model. In this context, normalization is the process of producing a canonical
+ * representation for models that physically look different but are semantically equivalent.
+ *
+ */
+public interface ModelNormalizer {
+
+ /**
+ * Merges duplicate elements like multiple declarations of the same build plugin in the specified model.
+ *
+ * @param model The model whose duplicate elements should be merged, must not be {@code null}.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ Model mergeDuplicates(Model model, ModelBuilderRequest request, ModelProblemCollector problems);
+
+ /**
+ * Sets default values in the specified model that for technical reasons cannot be set directly in the Modello
+ * definition.
+ *
+ * @param model The model in which to set the default values, must not be {@code null}.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ Model injectDefaultValues(Model model, ModelBuilderRequest request, ModelProblemCollector problems);
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelPathTranslator.java
similarity index 50%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelPathTranslator.java
index ca4c40d48a..07a36b9549 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelPathTranslator.java
@@ -16,28 +16,27 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api.services;
+package org.apache.maven.api.services.model;
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Nonnull;
+import java.nio.file.Path;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
/**
- * Access to {@link Type} registry.
+ * Resolves relative paths of a model against a specific base directory.
*
- * @since 4.0.0
*/
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
+public interface ModelPathTranslator {
/**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
+ * Resolves the well-known paths of the specified model against the given base directory. Paths within plugin
+ * configuration are not processed.
*
- * @param id the id of the type to retrieve
- * @return the type
+ * @param model The model whose paths should be resolved, may be {@code null}.
+ * @param basedir The base directory to resolve relative paths against, may be {@code null}.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @since 4.0.0
*/
- @Nonnull
- Type require(@Nonnull String id);
+ Model alignToBaseDirectory(Model model, Path basedir, ModelBuilderRequest request);
}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelProcessor.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelProcessor.java
new file mode 100644
index 0000000000..eb1c46e27a
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelProcessor.java
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import java.io.IOException;
+import java.nio.file.Path;
+
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.Nullable;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.xml.XmlReaderException;
+import org.apache.maven.api.services.xml.XmlReaderRequest;
+
+/**
+ * ModelProcessor
+ */
+public interface ModelProcessor {
+
+ /**
+ * Returns the file containing the pom to be parsed or null if a pom can not be found
+ * at the given file or in the given directory.
+ */
+ @Nullable
+ Path locateExistingPom(@Nonnull Path project);
+
+ /**
+ * Reads the model from the specified byte stream. The stream will be automatically closed before the method
+ * returns.
+ *
+ * @param request The reader request to deserialize the model, must not be {@code null}.
+ * @return The deserialized model, never {@code null}.
+ * @throws IOException If the model could not be deserialized.
+ * @throws XmlReaderException If the input format could not be parsed.
+ */
+ Model read(XmlReaderRequest request) throws IOException, XmlReaderException;
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelUrlNormalizer.java
similarity index 57%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelUrlNormalizer.java
index ca4c40d48a..221e233d8d 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelUrlNormalizer.java
@@ -16,28 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api.services;
+package org.apache.maven.api.services.model;
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
/**
- * Access to {@link Type} registry.
+ * Normalizes URLs to remove the ugly parent references "../" that got potentially inserted by URL adjustment during
+ * model inheritance.
*
- * @since 4.0.0
*/
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
+public interface ModelUrlNormalizer {
/**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
+ * Normalizes the well-known URLs of the specified model.
*
- * @param id the id of the type to retrieve
- * @return the type
+ * @param model The model whose URLs should be normalized, may be {@code null}.
+ * @param request The model building request that holds further settings, must not be {@code null}.
*/
- @Nonnull
- Type require(@Nonnull String id);
+ Model normalize(Model model, ModelBuilderRequest request);
}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelValidator.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelValidator.java
new file mode 100644
index 0000000000..de45f9d5a5
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelValidator.java
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Checks the model for missing or invalid values.
+ *
+ */
+public interface ModelValidator {
+ /**
+ * Checks the specified file model for missing or invalid values. This model is directly created from the POM
+ * file and has not been subjected to inheritance, interpolation or profile/default injection.
+ *
+ * @param model The model to validate, must not be {@code null}.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ default void validateFileModel(Model model, ModelBuilderRequest request, ModelProblemCollector problems) {
+ // do nothing
+ }
+
+ /**
+ * Checks the specified (raw) model for missing or invalid values. The raw model is the file model + buildpom filter
+ * transformation and has not been subjected to inheritance, interpolation or profile/default injection.
+ *
+ * @param model The model to validate, must not be {@code null}.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ void validateRawModel(Model model, ModelBuilderRequest request, ModelProblemCollector problems);
+
+ /**
+ * Checks the specified (effective) model for missing or invalid values. The effective model is fully assembled and
+ * has undergone inheritance, interpolation and other model operations.
+ *
+ * @param model The model to validate, must not be {@code null}.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ void validateEffectiveModel(Model model, ModelBuilderRequest request, ModelProblemCollector problems);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelVersionParser.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelVersionParser.java
new file mode 100644
index 0000000000..c14b34e93a
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelVersionParser.java
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import org.apache.maven.api.Version;
+import org.apache.maven.api.VersionConstraint;
+import org.apache.maven.api.VersionRange;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.services.VersionParserException;
+
+/**
+ * Model builder specific version parser. It is intentionally not
+ * {@link org.apache.maven.api.services.VersionParser} as this is not a service,
+ * but at Maven runtime it MAY actually use that service.
+ *
+ * @since 4.0.0
+ */
+public interface ModelVersionParser {
+
+ /**
+ * Parses the specified version string, for example "1.0".
+ *
+ * @param version the version string to parse, must not be {@code null}
+ * @return the parsed version, never {@code null}
+ * @throws VersionParserException if the string violates the syntax rules of this scheme
+ */
+ @Nonnull
+ Version parseVersion(@Nonnull String version);
+
+ /**
+ * Parses the specified version range specification, for example "[1.0,2.0)".
+ *
+ * @param range the range specification to parse, must not be {@code null}
+ * @return the parsed version range, never {@code null}
+ * @throws VersionParserException if the range specification violates the syntax rules of this scheme
+ */
+ @Nonnull
+ VersionRange parseVersionRange(@Nonnull String range);
+
+ /**
+ * Parses the specified version constraint specification, for example "1.0" or "[1.0,2.0)".
+ *
+ * @param constraint the range specification to parse, must not be {@code null}
+ * @return the parsed version constraint, never {@code null}
+ * @throws VersionParserException if the range specification violates the syntax rules of this scheme
+ */
+ @Nonnull
+ VersionConstraint parseVersionConstraint(@Nonnull String constraint);
+
+ /**
+ * Checks whether a given artifact version is considered a {@code SNAPSHOT} or not.
+ */
+ boolean isSnapshot(@Nonnull String version);
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelVersionProcessor.java
similarity index 52%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelVersionProcessor.java
index ca4c40d48a..8867441f09 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ModelVersionProcessor.java
@@ -16,28 +16,29 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api.services;
+package org.apache.maven.api.services.model;
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Nonnull;
+import java.util.Properties;
+
+import org.apache.maven.api.services.ModelBuilderRequest;
/**
- * Access to {@link Type} registry.
- *
- * @since 4.0.0
+ * Allows a fixed set of properties that are valid inside a version and that could be overwritten for example on the
+ * commandline
*/
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
+public interface ModelVersionProcessor {
+
+ /**
+ * @param property the property to check
+ * @return <code>true</code> if this is a valid property for this processor
+ */
+ boolean isValidProperty(String property);
/**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
+ * This method is responsible for examining the request and possibly overwrite of the valid properties in the model
*
- * @param id the id of the type to retrieve
- * @return the type
+ * @param modelProperties
+ * @param request
*/
- @Nonnull
- Type require(@Nonnull String id);
+ void overwriteModelProperties(Properties modelProperties, ModelBuilderRequest request);
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/PathTranslator.java
similarity index 53%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to maven-api-impl/src/main/java/org/apache/maven/api/services/model/PathTranslator.java
index ca4c40d48a..8f1fec0b57 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/PathTranslator.java
@@ -16,28 +16,25 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api.services;
+package org.apache.maven.api.services.model;
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Nonnull;
+import java.nio.file.Path;
/**
- * Access to {@link Type} registry.
+ * Resolves relative paths against a specific base directory.
*
- * @since 4.0.0
*/
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
+public interface PathTranslator {
/**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
+ * Resolves the specified path against the given base directory. The resolved path will be absolute and uses the
+ * platform-specific file separator if a base directory is given. Otherwise, the input path will be returned
+ * unaltered.
*
- * @param id the id of the type to retrieve
- * @return the type
+ * @param path The path to resolve, may be {@code null}.
+ * @param basedir The base directory to resolve relative paths against, may be {@code null}.
+ * @return The resolved path or {@code null} if the input path was {@code null}.
+ * @since 4.0.0
*/
- @Nonnull
- Type require(@Nonnull String id);
+ String alignToBaseDirectory(String path, Path basedir);
}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/PluginConfigurationExpander.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/PluginConfigurationExpander.java
new file mode 100644
index 0000000000..2481a583d6
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/PluginConfigurationExpander.java
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Handles expansion of general build plugin configuration into individual executions.
+ *
+ */
+public interface PluginConfigurationExpander {
+
+ /**
+ * Merges values from general build plugin configuration into the individual plugin executions of the given model.
+ *
+ * @param model The model whose build plugin configuration should be expanded, must not be <code>null</code>.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ Model expandPluginConfiguration(Model model, ModelBuilderRequest request, ModelProblemCollector problems);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/PluginManagementInjector.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/PluginManagementInjector.java
new file mode 100644
index 0000000000..9733e253ac
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/PluginManagementInjector.java
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Handles injection of plugin management into the model.
+ *
+ */
+public interface PluginManagementInjector {
+
+ /**
+ * Merges default values from the plugin management section of the given model into itself.
+ *
+ * @param model The model into which to merge the values specified by its plugin management section, must not be
+ * <code>null</code>.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ Model injectManagement(Model model, ModelBuilderRequest request, ModelProblemCollector problems);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileActivationContext.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileActivationContext.java
new file mode 100644
index 0000000000..8c1750342b
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileActivationContext.java
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Describes the environmental context used to determine the activation status of profiles.
+ *
+ */
+public interface ProfileActivationContext {
+ /**
+ * Key of the property containing the project's packaging.
+ * Available in {@link #getUserProperties()}.
+ * @since 4.0.0
+ */
+ String PROPERTY_NAME_PACKAGING = "packaging";
+
+ /**
+ * Gets the identifiers of those profiles that should be activated by explicit demand.
+ *
+ * @return The identifiers of those profiles to activate, never {@code null}.
+ */
+ List<String> getActiveProfileIds();
+
+ /**
+ * Gets the identifiers of those profiles that should be deactivated by explicit demand.
+ *
+ * @return The identifiers of those profiles to deactivate, never {@code null}.
+ */
+ List<String> getInactiveProfileIds();
+
+ /**
+ * Gets the system properties to use for interpolation and profile activation. The system properties are collected
+ * from the runtime environment like {@link System#getProperties()} and environment variables.
+ *
+ * @return The execution properties, never {@code null}.
+ */
+ Map<String, String> getSystemProperties();
+
+ /**
+ * Gets the user properties to use for interpolation and profile activation. The user properties have been
+ * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command
+ * line.
+ *
+ * @return The user properties, never {@code null}.
+ */
+ Map<String, String> getUserProperties();
+
+ /**
+ * Gets the base directory of the current project (if any).
+ *
+ * @return The base directory of the current project or {@code null} if none.
+ */
+ Path getProjectDirectory();
+
+ /**
+ * Gets current calculated project properties
+ *
+ * @return The project properties, never {@code null}.
+ */
+ Map<String, String> getProjectProperties();
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileActivator.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileActivator.java
new file mode 100644
index 0000000000..99153fa557
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileActivator.java
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import org.apache.maven.api.model.Profile;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Determines whether a profile should be activated.
+ *
+ */
+public interface ProfileActivator {
+
+ /**
+ * Determines whether the specified profile is active in the given activator context.
+ *
+ * @param profile The profile whose activation status should be determined, must not be {@code null}.
+ * @param context The environmental context used to determine the activation status of the profile, must not be
+ * {@code null}.
+ * @param problems The container used to collect problems (e.g. bad syntax) that were encountered, must not be
+ * {@code null}.
+ * @return {@code true} if the profile is active, {@code false} otherwise.
+ */
+ boolean isActive(Profile profile, ProfileActivationContext context, ModelProblemCollector problems);
+
+ /**
+ * Determines whether specified activation method is present in configuration or not. It should help to have AND
+ * between activation conditions
+ * Need for solving https://issues.apache.org/jira/browse/MNG-4565
+ * @param profile The profile whose activation status should be determined, must not be {@code null}.
+ * @param context The environmental context used to determine the activation status of the profile, must not be
+ * {@code null}.
+ * @param problems The container used to collect problems (e.g. bad syntax) that were encountered, must not be
+ * {@code null}.
+ * @return {@code true} if the profile is active, {@code false} otherwise.
+ */
+ boolean presentInConfig(Profile profile, ProfileActivationContext context, ModelProblemCollector problems);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileInjector.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileInjector.java
new file mode 100644
index 0000000000..87eb50abe3
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileInjector.java
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import java.util.List;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Profile;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Handles profile injection into the model.
+ *
+ */
+public interface ProfileInjector {
+
+ /**
+ * Merges values from the specified profile into the given model. Implementations are expected to keep the profile
+ * and model completely decoupled by injecting deep copies rather than the original objects from the profile.
+ *
+ * @param model The model into which to merge the values defined by the profile, must not be <code>null</code>.
+ * @param profile The (read-only) profile whose values should be injected, may be <code>null</code>.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ default Model injectProfile(
+ Model model, Profile profile, ModelBuilderRequest request, ModelProblemCollector problems) {
+ return injectProfiles(model, List.of(profile), request, problems);
+ }
+
+ /**
+ * Merges values from the specified profile into the given model. Implementations are expected to keep the profile
+ * and model completely decoupled by injecting deep copies rather than the original objects from the profile.
+ *
+ * @param model The model into which to merge the values defined by the profile, must not be <code>null</code>.
+ * @param profiles The (read-only) list of profiles whose values should be injected, must not be <code>null</code>.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ */
+ Model injectProfiles(
+ Model model, List<Profile> profiles, ModelBuilderRequest request, ModelProblemCollector problems);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileSelector.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileSelector.java
new file mode 100644
index 0000000000..b85cdd43eb
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/ProfileSelector.java
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.maven.api.model.Profile;
+import org.apache.maven.api.services.ModelProblemCollector;
+
+/**
+ * Calculates the active profiles among a given collection of profiles.
+ *
+ */
+public interface ProfileSelector {
+
+ /**
+ * Determines the profiles which are active in the specified activation context. Active profiles will eventually be
+ * injected into the model.
+ *
+ * @param profiles The profiles whose activation status should be determined, must not be {@code null}.
+ * @param context The environmental context used to determine the activation status of a profile, must not be
+ * {@code null}.
+ * @param problems The container used to collect problems that were encountered, must not be {@code null}.
+ * @return The profiles that have been activated, never {@code null}.
+ */
+ List<Profile> getActiveProfiles(
+ Collection<Profile> profiles, ProfileActivationContext context, ModelProblemCollector problems);
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/api/services/model/RootLocator.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/RootLocator.java
new file mode 100644
index 0000000000..505dbbe12a
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/RootLocator.java
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+package org.apache.maven.api.services.model;
+
+import java.nio.file.Path;
+
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.Nullable;
+
+/**
+ * Interface used to locate the root directory for a given project.
+ *
+ * The root locator is usually looked up from the plexus container.
+ * One notable exception is the computation of the early {@code session.rootDirectory}
+ * property which happens very early. The implementation used in this case
+ * will be discovered using the JDK service mechanism.
+ *
+ * The default implementation will look for a {@code .mvn} child directory
+ * or a {@code pom.xml} containing the {@code root="true"} attribute.
+ */
+public interface RootLocator {
+
+ String UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE = "Unable to find the root directory. "
+ + "Create a .mvn directory in the root directory or add the root=\"true\""
+ + " attribute on the root project's model to identify it.";
+
+ @Nonnull
+ default Path findMandatoryRoot(Path basedir) {
+ Path rootDirectory = findRoot(basedir);
+ if (rootDirectory == null) {
+ throw new IllegalStateException(getNoRootMessage());
+ }
+ return rootDirectory;
+ }
+
+ @Nullable
+ default Path findRoot(Path basedir) {
+ Path rootDirectory = basedir;
+ while (rootDirectory != null && !isRootDirectory(rootDirectory)) {
+ rootDirectory = rootDirectory.getParent();
+ }
+ return rootDirectory;
+ }
+
+ @Nonnull
+ default String getNoRootMessage() {
+ return UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE;
+ }
+
+ boolean isRootDirectory(Path dir);
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/UrlNormalizer.java
similarity index 57%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to maven-api-impl/src/main/java/org/apache/maven/api/services/model/UrlNormalizer.java
index ca4c40d48a..29dab47f05 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/UrlNormalizer.java
@@ -16,28 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api.services;
+package org.apache.maven.api.services.model;
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Nonnull;
-
-/**
- * Access to {@link Type} registry.
- *
- * @since 4.0.0
- */
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
+public interface UrlNormalizer {
/**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
+ * Normalizes the specified URL.
*
- * @param id the id of the type to retrieve
- * @return the type
+ * @param url The URL to normalize, may be {@code null}.
+ * @return The normalized URL or {@code null} if the input was {@code null}.
*/
- @Nonnull
- Type require(@Nonnull String id);
+ String normalize(String url);
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/WorkspaceModelResolver.java
similarity index 56%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to maven-api-impl/src/main/java/org/apache/maven/api/services/model/WorkspaceModelResolver.java
index ca4c40d48a..4dd18968d5 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/api/services/model/WorkspaceModelResolver.java
@@ -16,28 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api.services;
+package org.apache.maven.api.services.model;
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.model.Model;
/**
- * Access to {@link Type} registry.
- *
- * @since 4.0.0
+ * WorkspaceModelResolver
*/
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
+public interface WorkspaceModelResolver {
+
+ Model resolveRawModel(String groupId, String artifactId, String versionConstraint);
- /**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
- *
- * @param id the id of the type to retrieve
- * @return the type
- */
- @Nonnull
- Type require(@Nonnull String id);
+ Model resolveEffectiveModel(String groupId, String artifactId, String versionConstraint);
}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java
index 8d3068c8a7..ca789501a7 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java
@@ -90,10 +90,11 @@ public abstract class AbstractSession implements InternalSession {
List<RemoteRepository> repositories,
List<org.eclipse.aether.repository.RemoteRepository> resolverRepositories,
Lookup lookup) {
- this.session = session;
+ this.session = nonNull(session, "session");
this.repositorySystem = repositorySystem;
this.repositories = getRepositories(repositories, resolverRepositories);
this.lookup = lookup;
+ this.session.getData().set(InternalSession.class, this);
}
@Override
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifact.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifact.java
index 563797f05c..405d730cab 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifact.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifact.java
@@ -24,7 +24,6 @@ import org.apache.maven.api.Artifact;
import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.Version;
import org.apache.maven.api.annotations.Nonnull;
-import org.apache.maven.repository.internal.DefaultModelVersionParser;
import static org.apache.maven.internal.impl.Utils.nonNull;
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependency.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependency.java
index 8137a2e2c9..a29a0bb165 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependency.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependency.java
@@ -28,7 +28,6 @@ import org.apache.maven.api.Type;
import org.apache.maven.api.Version;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
-import org.apache.maven.repository.internal.DefaultModelVersionParser;
import org.eclipse.aether.artifact.ArtifactProperties;
import static org.apache.maven.internal.impl.Utils.nonNull;
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelUrlNormalizer.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelUrlNormalizer.java
new file mode 100644
index 0000000000..f593ed4301
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelUrlNormalizer.java
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl;
+
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.DistributionManagement;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Scm;
+import org.apache.maven.api.model.Site;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.model.ModelUrlNormalizer;
+import org.apache.maven.api.services.model.UrlNormalizer;
+
+/**
+ * Normalizes URLs to remove the ugly parent references "../" that got potentially inserted by URL adjustment during
+ * model inheritance.
+ *
+ */
+@Named
+@Singleton
+public class DefaultModelUrlNormalizer implements ModelUrlNormalizer {
+
+ private final UrlNormalizer urlNormalizer;
+
+ @Inject
+ public DefaultModelUrlNormalizer(UrlNormalizer urlNormalizer) {
+ this.urlNormalizer = urlNormalizer;
+ }
+
+ @Override
+ public Model normalize(Model model, ModelBuilderRequest request) {
+ if (model == null) {
+ return null;
+ }
+
+ Model.Builder builder = Model.newBuilder(model);
+ builder.url(normalize(model.getUrl()));
+
+ Scm scm = model.getScm();
+ if (scm != null) {
+ builder.scm(Scm.newBuilder(scm)
+ .url(normalize(scm.getUrl()))
+ .connection(normalize(scm.getConnection()))
+ .developerConnection(normalize(scm.getDeveloperConnection()))
+ .build());
+ }
+
+ DistributionManagement dist = model.getDistributionManagement();
+ if (dist != null) {
+ Site site = dist.getSite();
+ if (site != null) {
+ builder.distributionManagement(dist.withSite(site.withUrl(normalize(site.getUrl()))));
+ }
+ }
+
+ return builder.build();
+ }
+
+ private String normalize(String url) {
+ return urlNormalizer.normalize(url);
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelVersionParser.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelVersionParser.java
new file mode 100644
index 0000000000..4d674d1838
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelVersionParser.java
@@ -0,0 +1,288 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl;
+
+import java.util.regex.Pattern;
+
+import org.apache.maven.api.Version;
+import org.apache.maven.api.VersionConstraint;
+import org.apache.maven.api.VersionRange;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.services.VersionParserException;
+import org.apache.maven.api.services.model.ModelVersionParser;
+import org.eclipse.aether.version.InvalidVersionSpecificationException;
+import org.eclipse.aether.version.VersionScheme;
+
+import static java.util.Objects.requireNonNull;
+
+@Named
+@Singleton
+public class DefaultModelVersionParser implements ModelVersionParser {
+ private static final String SNAPSHOT = "SNAPSHOT";
+ private static final Pattern SNAPSHOT_TIMESTAMP = Pattern.compile("^(.*-)?([0-9]{8}\\.[0-9]{6}-[0-9]+)$");
+ private final VersionScheme versionScheme;
+
+ @Inject
+ public DefaultModelVersionParser(VersionScheme versionScheme) {
+ this.versionScheme = requireNonNull(versionScheme, "versionScheme");
+ }
+
+ @Override
+ public Version parseVersion(String version) {
+ requireNonNull(version, "version");
+ return new DefaultVersion(versionScheme, version);
+ }
+
+ @Override
+ public VersionRange parseVersionRange(String range) {
+ requireNonNull(range, "range");
+ return new DefaultVersionRange(versionScheme, range);
+ }
+
+ @Override
+ public boolean isSnapshot(String version) {
+ return checkSnapshot(version);
+ }
+
+ public static boolean checkSnapshot(String version) {
+ return version.endsWith(SNAPSHOT) || SNAPSHOT_TIMESTAMP.matcher(version).matches();
+ }
+
+ @Override
+ public VersionConstraint parseVersionConstraint(String constraint) {
+ requireNonNull(constraint, "constraint");
+ return new DefaultVersionConstraint(versionScheme, constraint);
+ }
+
+ static class DefaultVersion implements Version {
+ private final VersionScheme versionScheme;
+ private final org.eclipse.aether.version.Version delegate;
+
+ DefaultVersion(VersionScheme versionScheme, org.eclipse.aether.version.Version delegate) {
+ this.versionScheme = versionScheme;
+ this.delegate = delegate;
+ }
+
+ DefaultVersion(VersionScheme versionScheme, String delegateValue) {
+ this.versionScheme = versionScheme;
+ try {
+ this.delegate = versionScheme.parseVersion(delegateValue);
+ } catch (InvalidVersionSpecificationException e) {
+ throw new VersionParserException("Unable to parse version: " + delegateValue, e);
+ }
+ }
+
+ @Override
+ public int compareTo(Version o) {
+ if (o instanceof DefaultVersion) {
+ return delegate.compareTo(((DefaultVersion) o).delegate);
+ } else {
+ return compareTo(new DefaultVersion(versionScheme, o.asString()));
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ DefaultVersion that = (DefaultVersion) o;
+ return delegate.equals(that.delegate);
+ }
+
+ @Override
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+
+ @Override
+ public String asString() {
+ return delegate.toString();
+ }
+
+ @Override
+ public String toString() {
+ return asString();
+ }
+ }
+
+ static class DefaultVersionRange implements VersionRange {
+ private final VersionScheme versionScheme;
+ private final org.eclipse.aether.version.VersionRange delegate;
+
+ DefaultVersionRange(VersionScheme versionScheme, org.eclipse.aether.version.VersionRange delegate) {
+ this.versionScheme = versionScheme;
+ this.delegate = delegate;
+ }
+
+ DefaultVersionRange(VersionScheme versionScheme, String delegateValue) {
+ this.versionScheme = versionScheme;
+ try {
+ this.delegate = versionScheme.parseVersionRange(delegateValue);
+ } catch (InvalidVersionSpecificationException e) {
+ throw new VersionParserException("Unable to parse version range: " + delegateValue, e);
+ }
+ }
+
+ @Override
+ public boolean contains(Version version) {
+ if (version instanceof DefaultVersion) {
+ return delegate.containsVersion(((DefaultVersion) version).delegate);
+ } else {
+ return contains(new DefaultVersion(versionScheme, version.asString()));
+ }
+ }
+
+ @Override
+ public Boundary getUpperBoundary() {
+ org.eclipse.aether.version.VersionRange.Bound bound = delegate.getUpperBound();
+ if (bound == null) {
+ return null;
+ }
+ return new Boundary() {
+ @Override
+ public Version getVersion() {
+ return new DefaultVersion(versionScheme, bound.getVersion());
+ }
+
+ @Override
+ public boolean isInclusive() {
+ return bound.isInclusive();
+ }
+ };
+ }
+
+ @Override
+ public Boundary getLowerBoundary() {
+ org.eclipse.aether.version.VersionRange.Bound bound = delegate.getLowerBound();
+ if (bound == null) {
+ return null;
+ }
+ return new Boundary() {
+ @Override
+ public Version getVersion() {
+ return new DefaultVersion(versionScheme, bound.getVersion());
+ }
+
+ @Override
+ public boolean isInclusive() {
+ return bound.isInclusive();
+ }
+ };
+ }
+
+ @Override
+ public String asString() {
+ return delegate.toString();
+ }
+
+ @Override
+ public String toString() {
+ return asString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ DefaultVersionRange that = (DefaultVersionRange) o;
+ return delegate.equals(that.delegate);
+ }
+
+ @Override
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+ }
+
+ static class DefaultVersionConstraint implements VersionConstraint {
+ private final VersionScheme versionScheme;
+ private final org.eclipse.aether.version.VersionConstraint delegate;
+
+ DefaultVersionConstraint(VersionScheme versionScheme, String delegateValue) {
+ this.versionScheme = versionScheme;
+ try {
+ this.delegate = versionScheme.parseVersionConstraint(delegateValue);
+ } catch (InvalidVersionSpecificationException e) {
+ throw new VersionParserException("Unable to parse version constraint: " + delegateValue, e);
+ }
+ }
+
+ @Override
+ public boolean contains(Version version) {
+ if (version instanceof DefaultVersion) {
+ return delegate.containsVersion(((DefaultVersion) version).delegate);
+ } else {
+ return contains(new DefaultVersion(versionScheme, version.asString()));
+ }
+ }
+
+ @Override
+ public String asString() {
+ return delegate.toString();
+ }
+
+ @Override
+ public VersionRange getVersionRange() {
+ if (delegate.getRange() == null) {
+ return null;
+ }
+ return new DefaultVersionRange(versionScheme, delegate.getRange());
+ }
+
+ @Override
+ public Version getRecommendedVersion() {
+ if (delegate.getVersion() == null) {
+ return null;
+ }
+ return new DefaultVersion(versionScheme, delegate.getVersion());
+ }
+
+ @Override
+ public String toString() {
+ return asString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ DefaultVersionConstraint that = (DefaultVersionConstraint) o;
+ return delegate.equals(that.delegate);
+ }
+
+ @Override
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelXmlFactory.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelXmlFactory.java
index d21f94fe2f..70cf3bd1ef 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelXmlFactory.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultModelXmlFactory.java
@@ -59,7 +59,8 @@ public class DefaultModelXmlFactory implements ModelXmlFactory {
try {
InputSource source = null;
if (request.getModelId() != null || request.getLocation() != null) {
- source = new InputSource(request.getModelId(), request.getLocation());
+ source = new InputSource(
+ request.getModelId(), path != null ? path.toUri().toString() : null);
}
MavenStaxReader xml = new MavenStaxReader();
xml.setAddDefaultEntities(request.isAddDefaultEntities());
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultPluginConfigurationExpander.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultPluginConfigurationExpander.java
new file mode 100644
index 0000000000..6a6b215323
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultPluginConfigurationExpander.java
@@ -0,0 +1,107 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Function;
+
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.Build;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Plugin;
+import org.apache.maven.api.model.PluginManagement;
+import org.apache.maven.api.model.ReportPlugin;
+import org.apache.maven.api.model.Reporting;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.services.model.PluginConfigurationExpander;
+import org.apache.maven.api.xml.XmlNode;
+
+/**
+ * Handles expansion of general build plugin configuration into individual executions.
+ *
+ */
+@Named
+@Singleton
+public class DefaultPluginConfigurationExpander implements PluginConfigurationExpander {
+
+ @Override
+ public Model expandPluginConfiguration(Model model, ModelBuilderRequest request, ModelProblemCollector problems) {
+ Build build = model.getBuild();
+ if (build != null) {
+ build = build.withPlugins(expandPlugin(build.getPlugins()));
+ PluginManagement pluginManagement = build.getPluginManagement();
+ if (pluginManagement != null) {
+ build = build.withPluginManagement(
+ pluginManagement.withPlugins(expandPlugin(pluginManagement.getPlugins())));
+ }
+ model = model.withBuild(build);
+ }
+ Reporting reporting = model.getReporting();
+ if (reporting != null) {
+ expandReport(reporting.getPlugins());
+ }
+ return model.withBuild(build);
+ }
+
+ private List<Plugin> expandPlugin(List<Plugin> oldPlugins) {
+ return map(oldPlugins, plugin -> {
+ XmlNode pluginConfiguration = plugin.getConfiguration();
+ if (pluginConfiguration != null) {
+ return plugin.withExecutions(map(
+ plugin.getExecutions(),
+ execution -> execution.withConfiguration(
+ XmlNode.merge(execution.getConfiguration(), pluginConfiguration))));
+ } else {
+ return plugin;
+ }
+ });
+ }
+
+ private List<ReportPlugin> expandReport(List<ReportPlugin> oldPlugins) {
+ return map(oldPlugins, plugin -> {
+ XmlNode pluginConfiguration = plugin.getConfiguration();
+ if (pluginConfiguration != null) {
+ return plugin.withReportSets(map(
+ plugin.getReportSets(),
+ report -> report.withConfiguration(
+ XmlNode.merge(report.getConfiguration(), pluginConfiguration))));
+ } else {
+ return plugin;
+ }
+ });
+ }
+
+ static <T> List<T> map(List<T> list, Function<T, T> mapper) {
+ List<T> newList = list;
+ for (int i = 0; i < newList.size(); i++) {
+ T oldT = newList.get(i);
+ T newT = mapper.apply(oldT);
+ if (newT != oldT) {
+ if (newList == list) {
+ newList = new ArrayList<>(list);
+ }
+ newList.set(i, newT);
+ }
+ }
+ return newList;
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultRemoteRepository.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultRemoteRepository.java
index 6a279f675f..dc41e41e99 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultRemoteRepository.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultRemoteRepository.java
@@ -55,4 +55,9 @@ public class DefaultRemoteRepository implements RemoteRepository {
public String getProtocol() {
return repository.getProtocol();
}
+
+ @Override
+ public String toString() {
+ return repository.toString();
+ }
}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultSettingsBuilder.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultSettingsBuilder.java
index 4801258d28..24b64f6436 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultSettingsBuilder.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultSettingsBuilder.java
@@ -137,11 +137,7 @@ public class DefaultSettingsBuilder implements SettingsBuilder {
Settings settings;
try {
- try {
- InputStream is = settingsSource.openStream();
- if (is == null) {
- return Settings.newInstance();
- }
+ try (InputStream is = settingsSource.openStream()) {
settings = request.getSession()
.getService(SettingsXmlFactory.class)
.read(XmlReaderRequest.builder()
@@ -150,25 +146,23 @@ public class DefaultSettingsBuilder implements SettingsBuilder {
.strict(true)
.build());
} catch (XmlReaderException e) {
- InputStream is = settingsSource.openStream();
- if (is == null) {
- return Settings.newInstance();
+ try (InputStream is = settingsSource.openStream()) {
+ settings = request.getSession()
+ .getService(SettingsXmlFactory.class)
+ .read(XmlReaderRequest.builder()
+ .inputStream(is)
+ .location(settingsSource.getLocation())
+ .strict(false)
+ .build());
+ Location loc = e.getCause() instanceof XMLStreamException xe ? xe.getLocation() : null;
+ problems.add(new DefaultBuilderProblem(
+ settingsSource.getLocation(),
+ loc != null ? loc.getLineNumber() : -1,
+ loc != null ? loc.getColumnNumber() : -1,
+ e,
+ e.getMessage(),
+ BuilderProblem.Severity.WARNING));
}
- settings = request.getSession()
- .getService(SettingsXmlFactory.class)
- .read(XmlReaderRequest.builder()
- .inputStream(is)
- .location(settingsSource.getLocation())
- .strict(false)
- .build());
- Location loc = e.getCause() instanceof XMLStreamException xe ? xe.getLocation() : null;
- problems.add(new DefaultBuilderProblem(
- settingsSource.getLocation(),
- loc != null ? loc.getLineNumber() : -1,
- loc != null ? loc.getColumnNumber() : -1,
- e,
- e.getMessage(),
- BuilderProblem.Severity.WARNING));
}
} catch (XmlReaderException e) {
Location loc = e.getCause() instanceof XMLStreamException xe ? xe.getLocation() : null;
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultSuperPomProvider.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultSuperPomProvider.java
new file mode 100644
index 0000000000..58f75895a4
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultSuperPomProvider.java
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.SuperPomProvider;
+import org.apache.maven.api.services.model.ModelProcessor;
+import org.apache.maven.api.services.xml.XmlReaderRequest;
+
+@Named
+@Singleton
+public class DefaultSuperPomProvider implements SuperPomProvider {
+
+ private final ModelProcessor modelProcessor;
+
+ /**
+ * The cached super POM, lazily created.
+ */
+ private static final Map<String, Model> SUPER_MODELS = new ConcurrentHashMap<>();
+
+ @Inject
+ public DefaultSuperPomProvider(ModelProcessor modelProcessor) {
+ this.modelProcessor = modelProcessor;
+ }
+
+ @Override
+ public Model getSuperPom(String version) {
+ return SUPER_MODELS.computeIfAbsent(Objects.requireNonNull(version), v -> readModel(version, v));
+ }
+
+ private Model readModel(String version, String v) {
+ String resource = "/org/apache/maven/model/pom-" + v + ".xml";
+ URL url = getClass().getResource(resource);
+ if (url == null) {
+ throw new IllegalStateException("The super POM " + resource + " was not found"
+ + ", please verify the integrity of your Maven installation");
+ }
+ try (InputStream is = url.openStream()) {
+ String modelId = "org.apache.maven:maven-model-builder:" + version + "-"
+ + this.getClass().getPackage().getImplementationVersion() + ":super-pom";
+ return modelProcessor.read(XmlReaderRequest.builder()
+ .modelId(modelId)
+ .location(url.toExternalForm())
+ .inputStream(is)
+ .strict(false)
+ .build());
+ } catch (IOException e) {
+ throw new IllegalStateException(
+ "The super POM " + resource + " is damaged"
+ + ", please verify the integrity of your Maven installation",
+ e);
+ }
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultUrlNormalizer.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultUrlNormalizer.java
new file mode 100644
index 0000000000..c3b7bcb5a5
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultUrlNormalizer.java
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl;
+
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.services.model.UrlNormalizer;
+
+/**
+ * Normalizes a URL.
+ *
+ */
+@Named
+@Singleton
+public class DefaultUrlNormalizer implements UrlNormalizer {
+
+ @Override
+ public String normalize(String url) {
+ String result = url;
+
+ if (result != null) {
+ while (true) {
+ int idx = result.indexOf("/../");
+ if (idx < 0) {
+ break;
+ } else if (idx == 0) {
+ result = result.substring(3);
+ continue;
+ }
+ int parent = idx - 1;
+ while (parent >= 0 && result.charAt(parent) == '/') {
+ parent--;
+ }
+ parent = result.lastIndexOf('/', parent);
+ if (parent < 0) {
+ result = result.substring(idx + 4);
+ } else {
+ result = result.substring(0, parent) + result.substring(idx + 3);
+ }
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionParser.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionParser.java
index 7e8ae11cbc..16d7b670bf 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionParser.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionParser.java
@@ -25,7 +25,7 @@ import org.apache.maven.api.di.Inject;
import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Singleton;
import org.apache.maven.api.services.VersionParser;
-import org.apache.maven.model.version.ModelVersionParser;
+import org.apache.maven.api.services.model.ModelVersionParser;
import static org.apache.maven.internal.impl.Utils.nonNull;
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionRangeResolver.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionRangeResolver.java
index 41e107698e..585fb6faf1 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionRangeResolver.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultVersionRangeResolver.java
@@ -66,8 +66,9 @@ public class DefaultVersionRangeResolver implements VersionRangeResolver {
session.toRepositories(session.getRemoteRepositories()),
null));
- Map<String, ArtifactRepository> repos =
- res.getVersions().stream().collect(Collectors.toMap(v -> v.toString(), res::getRepository));
+ Map<String, ArtifactRepository> repos = res.getVersions().stream()
+ .filter(v -> res.getRepository(v) != null)
+ .collect(Collectors.toMap(v -> v.toString(), res::getRepository));
return new VersionRangeResolverResult() {
@Override
diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/ExtensibleEnumRegistries.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/ExtensibleEnumRegistries.java
similarity index 72%
rename from maven-core/src/main/java/org/apache/maven/internal/impl/ExtensibleEnumRegistries.java
rename to maven-api-impl/src/main/java/org/apache/maven/internal/impl/ExtensibleEnumRegistries.java
index e661a40397..f8bc69e538 100644
--- a/maven-core/src/main/java/org/apache/maven/internal/impl/ExtensibleEnumRegistries.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/ExtensibleEnumRegistries.java
@@ -18,21 +18,29 @@
*/
package org.apache.maven.internal.impl;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Optional;
-import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.apache.maven.SessionScoped;
-import org.apache.maven.api.*;
-import org.apache.maven.api.services.*;
-import org.apache.maven.api.spi.*;
+import org.apache.maven.api.ExtensibleEnum;
+import org.apache.maven.api.Language;
+import org.apache.maven.api.PathScope;
+import org.apache.maven.api.ProjectScope;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.SessionScoped;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.services.ExtensibleEnumRegistry;
+import org.apache.maven.api.services.LanguageRegistry;
+import org.apache.maven.api.services.PathScopeRegistry;
+import org.apache.maven.api.services.ProjectScopeRegistry;
+import org.apache.maven.api.spi.ExtensibleEnumProvider;
+import org.apache.maven.api.spi.LanguageProvider;
+import org.apache.maven.api.spi.PathScopeProvider;
+import org.apache.maven.api.spi.ProjectScopeProvider;
import static org.apache.maven.internal.impl.Utils.nonNull;
@@ -76,7 +84,8 @@ public class ExtensibleEnumRegistries {
}
}
- static class DefaultExtensibleEnumRegistry<T extends ExtensibleEnum, P extends ExtensibleEnumProvider<T>>
+ public abstract static class DefaultExtensibleEnumRegistry<
+ T extends ExtensibleEnum, P extends ExtensibleEnumProvider<T>>
implements ExtensibleEnumRegistry<T> {
protected final Map<String, T> values;
@@ -84,12 +93,12 @@ public class ExtensibleEnumRegistries {
DefaultExtensibleEnumRegistry(List<P> providers, T... builtinValues) {
values = Stream.<T>concat(
Stream.of(builtinValues), providers.stream().flatMap(p -> p.provides().stream()))
- .collect(Collectors.toUnmodifiableMap(ExtensibleEnum::id, Function.identity()));
+ .collect(Collectors.toUnmodifiableMap(t -> t.id().toLowerCase(Locale.ROOT), t -> t));
}
@Override
public Optional<T> lookup(String id) {
- return Optional.ofNullable(values.get(nonNull(id, "id")));
+ return Optional.ofNullable(values.get(nonNull(id, "id").toLowerCase(Locale.ROOT)));
}
}
}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/InternalSession.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/InternalSession.java
index 0b5bf1874c..3d4107fc94 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/InternalSession.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/InternalSession.java
@@ -41,6 +41,10 @@ public interface InternalSession extends Session {
return cast(InternalSession.class, session, "session should be an " + InternalSession.class);
}
+ static InternalSession from(org.eclipse.aether.RepositorySystemSession session) {
+ return cast(InternalSession.class, session.getData().get(InternalSession.class), "session");
+ }
+
RemoteRepository getRemoteRepository(org.eclipse.aether.repository.RemoteRepository repository);
Node getNode(org.eclipse.aether.graph.DependencyNode node);
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/Utils.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/Utils.java
index 3077ac6bd9..0d0d43c32f 100644
--- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/Utils.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/Utils.java
@@ -40,6 +40,9 @@ class Utils {
static <T> T cast(Class<T> clazz, Object o, String name) {
if (!clazz.isInstance(o)) {
+ if (o == null) {
+ throw new IllegalArgumentException(name + " is null");
+ }
throw new IllegalArgumentException(name + " is not an instance of " + clazz.getName());
}
return clazz.cast(o);
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/BuildModelTransformer.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/BuildModelTransformer.java
new file mode 100644
index 0000000000..cc48498afe
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/BuildModelTransformer.java
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.Dependency;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Parent;
+import org.apache.maven.api.services.ModelTransformer;
+import org.apache.maven.api.services.ModelTransformerContext;
+
+/**
+ * ModelSourceTransformer for the build pom
+ *
+ * @since 4.0.0
+ */
+@Named
+@Singleton
+public class BuildModelTransformer implements ModelTransformer {
+
+ public static final String NAMESPACE_PREFIX = "http://maven.apache.org/POM/";
+
+ @Override
+ public Model transform(ModelTransformerContext context, Model model, Path path) {
+ Model.Builder builder = Model.newBuilder(model);
+ handleModelVersion(context, model, path, builder);
+ handleParent(context, model, path, builder);
+ handleReactorDependencies(context, model, path, builder);
+ handleCiFriendlyVersion(context, model, path, builder);
+ return builder.build();
+ }
+
+ //
+ // Infer modelVersion from namespace URI
+ //
+ void handleModelVersion(ModelTransformerContext context, Model model, Path pomFile, Model.Builder builder) {
+ String namespace = model.getNamespaceUri();
+ if (model.getModelVersion() == null && namespace != null && namespace.startsWith(NAMESPACE_PREFIX)) {
+ builder.modelVersion(namespace.substring(NAMESPACE_PREFIX.length()));
+ }
+ }
+
+ //
+ // Infer parent information
+ //
+ void handleParent(ModelTransformerContext context, Model model, Path pomFile, Model.Builder builder) {
+ Parent parent = model.getParent();
+ if (parent != null) {
+ String version = parent.getVersion();
+ String path = Optional.ofNullable(parent.getRelativePath()).orElse("..");
+ if (version == null && !path.isEmpty()) {
+ Optional<RelativeProject> resolvedParent = resolveRelativePath(
+ pomFile, context, Paths.get(path), parent.getGroupId(), parent.getArtifactId());
+ if (resolvedParent.isPresent()) {
+ version = resolvedParent.get().getVersion();
+ }
+ }
+ // CI Friendly version for parent
+ String modVersion = replaceCiFriendlyVersion(context, version);
+ builder.parent(parent.withVersion(modVersion));
+ }
+ }
+
+ //
+ // CI friendly versions
+ //
+ void handleCiFriendlyVersion(ModelTransformerContext context, Model model, Path pomFile, Model.Builder builder) {
+ String version = model.getVersion();
+ String modVersion = replaceCiFriendlyVersion(context, version);
+ builder.version(modVersion);
+ }
+
+ //
+ // Infer inner reactor dependencies version
+ //
+ void handleReactorDependencies(ModelTransformerContext context, Model model, Path pomFile, Model.Builder builder) {
+ List<Dependency> newDeps = new ArrayList<>();
+ boolean modified = false;
+ for (Dependency dep : model.getDependencies()) {
+ if (dep.getVersion() == null) {
+ Model depModel = context.getRawModel(model.getPomFile(), dep.getGroupId(), dep.getArtifactId());
+ if (depModel != null) {
+ String v = depModel.getVersion();
+ if (v == null && depModel.getParent() != null) {
+ v = depModel.getParent().getVersion();
+ }
+ dep = dep.withVersion(v);
+ modified = true;
+ }
+ }
+ newDeps.add(dep);
+ }
+ if (modified) {
+ builder.dependencies(newDeps);
+ }
+ }
+
+ protected String replaceCiFriendlyVersion(ModelTransformerContext context, String version) {
+ if (version != null) {
+ for (String key : Arrays.asList("changelist", "revision", "sha1")) {
+ String val = context.getUserProperty(key);
+ if (val != null) {
+ version = version.replace("${" + key + "}", val);
+ }
+ }
+ }
+ return version;
+ }
+
+ protected Optional<RelativeProject> resolveRelativePath(
+ Path pomFile, ModelTransformerContext context, Path relativePath, String groupId, String artifactId) {
+ Path pomPath = pomFile.resolveSibling(relativePath).normalize();
+ if (Files.isDirectory(pomPath)) {
+ pomPath = context.locate(pomPath);
+ }
+
+ if (pomPath == null || !Files.isRegularFile(pomPath)) {
+ return Optional.empty();
+ }
+
+ Optional<RelativeProject> mappedProject = Optional.ofNullable(context.getRawModel(pomFile, pomPath.normalize()))
+ .map(BuildModelTransformer::toRelativeProject);
+
+ if (mappedProject.isPresent()) {
+ RelativeProject project = mappedProject.get();
+
+ if (Objects.equals(groupId, project.getGroupId()) && Objects.equals(artifactId, project.getArtifactId())) {
+ return mappedProject;
+ }
+ }
+ return Optional.empty();
+ }
+
+ private static RelativeProject toRelativeProject(final Model m) {
+ String groupId = m.getGroupId();
+ if (groupId == null && m.getParent() != null) {
+ groupId = m.getParent().getGroupId();
+ }
+
+ String version = m.getVersion();
+ if (version == null && m.getParent() != null) {
+ version = m.getParent().getVersion();
+ }
+
+ return new RelativeProject(groupId, m.getArtifactId(), version);
+ }
+
+ protected static class RelativeProject {
+ private final String groupId;
+
+ private final String artifactId;
+
+ private final String version;
+
+ protected RelativeProject(String groupId, String artifactId, String version) {
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ }
+
+ public String getGroupId() {
+ return groupId;
+ }
+
+ public String getArtifactId() {
+ return artifactId;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultDependencyManagementImporter.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultDependencyManagementImporter.java
new file mode 100644
index 0000000000..975c8e7b9a
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultDependencyManagementImporter.java
@@ -0,0 +1,147 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.Dependency;
+import org.apache.maven.api.model.DependencyManagement;
+import org.apache.maven.api.model.Exclusion;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.BuilderProblem.Severity;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblem.Version;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.services.model.*;
+
+/**
+ * Handles the import of dependency management from other models into the target model.
+ *
+ */
+@Named
+@Singleton
+public class DefaultDependencyManagementImporter implements DependencyManagementImporter {
+
+ @Override
+ public Model importManagement(
+ Model target,
+ List<? extends DependencyManagement> sources,
+ ModelBuilderRequest request,
+ ModelProblemCollector problems) {
+ if (sources != null && !sources.isEmpty()) {
+ Map<String, Dependency> dependencies = new LinkedHashMap<>();
+
+ DependencyManagement depMgmt = target.getDependencyManagement();
+
+ if (depMgmt != null) {
+ for (Dependency dependency : depMgmt.getDependencies()) {
+ dependencies.put(dependency.getManagementKey(), dependency);
+ }
+ } else {
+ depMgmt = DependencyManagement.newInstance();
+ }
+
+ Set<String> directDependencies = new HashSet<>(dependencies.keySet());
+
+ for (DependencyManagement source : sources) {
+ for (Dependency dependency : source.getDependencies()) {
+ String key = dependency.getManagementKey();
+ Dependency present = dependencies.putIfAbsent(key, dependency);
+ if (present != null && !equals(dependency, present) && !directDependencies.contains(key)) {
+ // TODO: https://issues.apache.org/jira/browse/MNG-8004
+ problems.add(
+ Severity.WARNING,
+ Version.V40,
+ "Ignored POM import for: " + toString(dependency) + " as already imported "
+ + toString(present) + ". Add a the conflicting managed dependency directly "
+ + "to the dependencyManagement section of the POM.");
+ }
+ }
+ }
+
+ return target.withDependencyManagement(depMgmt.withDependencies(dependencies.values()));
+ }
+ return target;
+ }
+
+ private String toString(Dependency dependency) {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder
+ .append(dependency.getGroupId())
+ .append(":")
+ .append(dependency.getArtifactId())
+ .append(":")
+ .append(dependency.getType());
+ if (dependency.getClassifier() != null && !dependency.getClassifier().isEmpty()) {
+ stringBuilder.append(":").append(dependency.getClassifier());
+ }
+ stringBuilder
+ .append(":")
+ .append(dependency.getVersion())
+ .append("@")
+ .append(dependency.getScope() == null ? "compile" : dependency.getScope());
+ if (dependency.isOptional()) {
+ stringBuilder.append("[optional]");
+ }
+ if (!dependency.getExclusions().isEmpty()) {
+ stringBuilder.append("[").append(dependency.getExclusions().size()).append(" exclusions]");
+ }
+ return stringBuilder.toString();
+ }
+
+ private boolean equals(Dependency d1, Dependency d2) {
+ return Objects.equals(d1.getGroupId(), d2.getGroupId())
+ && Objects.equals(d1.getArtifactId(), d2.getArtifactId())
+ && Objects.equals(d1.getVersion(), d2.getVersion())
+ && Objects.equals(d1.getType(), d2.getType())
+ && Objects.equals(d1.getClassifier(), d2.getClassifier())
+ && Objects.equals(d1.getScope(), d2.getScope())
+ && Objects.equals(d1.getSystemPath(), d2.getSystemPath())
+ && Objects.equals(d1.getOptional(), d2.getOptional())
+ && equals(d1.getExclusions(), d2.getExclusions());
+ }
+
+ private boolean equals(Collection<Exclusion> ce1, Collection<Exclusion> ce2) {
+ if (ce1.size() == ce2.size()) {
+ Iterator<Exclusion> i1 = ce1.iterator();
+ Iterator<Exclusion> i2 = ce2.iterator();
+ while (i1.hasNext() && i2.hasNext()) {
+ if (!equals(i1.next(), i2.next())) {
+ return false;
+ }
+ }
+ return !i1.hasNext() && !i2.hasNext();
+ }
+ return false;
+ }
+
+ private boolean equals(Exclusion e1, Exclusion e2) {
+ return Objects.equals(e1.getGroupId(), e2.getGroupId())
+ && Objects.equals(e1.getArtifactId(), e2.getArtifactId());
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultDependencyManagementInjector.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultDependencyManagementInjector.java
new file mode 100644
index 0000000000..b249b828ee
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultDependencyManagementInjector.java
@@ -0,0 +1,119 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.Dependency;
+import org.apache.maven.api.model.DependencyManagement;
+import org.apache.maven.api.model.Exclusion;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.services.model.*;
+
+/**
+ * Handles injection of dependency management into the model.
+ *
+ */
+@SuppressWarnings({"checkstyle:methodname"})
+@Named
+@Singleton
+public class DefaultDependencyManagementInjector implements DependencyManagementInjector {
+
+ private ManagementModelMerger merger = new ManagementModelMerger();
+
+ @Override
+ public Model injectManagement(Model model, ModelBuilderRequest request, ModelProblemCollector problems) {
+ return merger.mergeManagedDependencies(model);
+ }
+
+ /**
+ * ManagementModelMerger
+ */
+ protected static class ManagementModelMerger extends MavenModelMerger {
+
+ public Model mergeManagedDependencies(Model model) {
+ DependencyManagement dependencyManagement = model.getDependencyManagement();
+ if (dependencyManagement != null) {
+ Map<Object, Dependency> dependencies = new HashMap<>();
+ Map<Object, Object> context = Collections.emptyMap();
+
+ for (Dependency dependency : model.getDependencies()) {
+ Object key = getDependencyKey().apply(dependency);
+ dependencies.put(key, dependency);
+ }
+
+ boolean modified = false;
+ for (Dependency managedDependency : dependencyManagement.getDependencies()) {
+ Object key = getDependencyKey().apply(managedDependency);
+ Dependency dependency = dependencies.get(key);
+ if (dependency != null) {
+ Dependency merged = mergeDependency(dependency, managedDependency, false, context);
+ if (merged != dependency) {
+ dependencies.put(key, merged);
+ modified = true;
+ }
+ }
+ }
+
+ if (modified) {
+ List<Dependency> newDeps = new ArrayList<>(dependencies.size());
+ for (Dependency dep : model.getDependencies()) {
+ Object key = getDependencyKey().apply(dep);
+ Dependency dependency = dependencies.get(key);
+ newDeps.add(dependency);
+ }
+ return Model.newBuilder(model).dependencies(newDeps).build();
+ }
+ }
+ return model;
+ }
+
+ @Override
+ protected void mergeDependency_Optional(
+ Dependency.Builder builder,
+ Dependency target,
+ Dependency source,
+ boolean sourceDominant,
+ Map<Object, Object> context) {
+ // optional flag is not managed
+ }
+
+ @Override
+ protected void mergeDependency_Exclusions(
+ Dependency.Builder builder,
+ Dependency target,
+ Dependency source,
+ boolean sourceDominant,
+ Map<Object, Object> context) {
+ List<Exclusion> tgt = target.getExclusions();
+ if (tgt.isEmpty()) {
+ List<Exclusion> src = source.getExclusions();
+ builder.exclusions(src);
+ }
+ }
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultInheritanceAssembler.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultInheritanceAssembler.java
new file mode 100644
index 0000000000..d00352165f
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultInheritanceAssembler.java
@@ -0,0 +1,330 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.InputLocation;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.ModelBase;
+import org.apache.maven.api.model.Plugin;
+import org.apache.maven.api.model.PluginContainer;
+import org.apache.maven.api.model.ReportPlugin;
+import org.apache.maven.api.model.Reporting;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.services.model.*;
+
+/**
+ * Handles inheritance of model values.
+ *
+ */
+@SuppressWarnings({"checkstyle:methodname"})
+@Named
+@Singleton
+public class DefaultInheritanceAssembler implements InheritanceAssembler {
+
+ private static final String CHILD_DIRECTORY = "child-directory";
+
+ private static final String CHILD_DIRECTORY_PROPERTY = "project.directory";
+
+ private final InheritanceModelMerger merger = new InheritanceModelMerger();
+
+ @Override
+ public Model assembleModelInheritance(
+ Model child, Model parent, ModelBuilderRequest request, ModelProblemCollector problems) {
+ Map<Object, Object> hints = new HashMap<>();
+ String childPath = child.getProperties().getOrDefault(CHILD_DIRECTORY_PROPERTY, child.getArtifactId());
+ hints.put(CHILD_DIRECTORY, childPath);
+ hints.put(MavenModelMerger.CHILD_PATH_ADJUSTMENT, getChildPathAdjustment(child, parent, childPath));
+ return merger.merge(child, parent, false, hints);
+ }
+
+ /**
+ * Calculates the relative path from the base directory of the parent to the parent directory of the base directory
+ * of the child. The general idea is to adjust inherited URLs to match the project layout (in SCM).
+ *
+ * <p>This calculation is only a heuristic based on our conventions.
+ * In detail, the algo relies on the following assumptions: <ul>
+ * <li>The parent uses aggregation and refers to the child via the modules section</li>
+ * <li>The module path to the child is considered to
+ * point at the POM rather than its base directory if the path ends with ".xml" (ignoring case)</li>
+ * <li>The name of the child's base directory matches the artifact id of the child.</li>
+ * </ul>
+ * Note that for the sake of independence from the user
+ * environment, the filesystem is intentionally not used for the calculation.</p>
+ *
+ * @param child The child model, must not be <code>null</code>.
+ * @param parent The parent model, may be <code>null</code>.
+ * @param childDirectory The directory defined in child model, may be <code>null</code>.
+ * @return The path adjustment, can be empty but never <code>null</code>.
+ */
+ private String getChildPathAdjustment(Model child, Model parent, String childDirectory) {
+ String adjustment = "";
+
+ if (parent != null) {
+ String childName = child.getArtifactId();
+
+ /*
+ * This logic (using filesystem, against wanted independence from the user environment) exists only for the
+ * sake of backward-compat with 2.x (MNG-5000). In general, it is wrong to
+ * base URL inheritance on the module directory names as this information is unavailable for POMs in the
+ * repository. In other words, modules where artifactId != moduleDirName will see different effective URLs
+ * depending on how the model was constructed (from filesystem or from repository).
+ */
+ if (child.getProjectDirectory() != null) {
+ childName = child.getProjectDirectory().getFileName().toString();
+ }
+
+ for (String module : parent.getModules()) {
+ module = module.replace('\\', '/');
+
+ if (module.regionMatches(true, module.length() - 4, ".xml", 0, 4)) {
+ module = module.substring(0, module.lastIndexOf('/') + 1);
+ }
+
+ String moduleName = module;
+ if (moduleName.endsWith("/")) {
+ moduleName = moduleName.substring(0, moduleName.length() - 1);
+ }
+
+ int lastSlash = moduleName.lastIndexOf('/');
+
+ moduleName = moduleName.substring(lastSlash + 1);
+
+ if ((moduleName.equals(childName) || (moduleName.equals(childDirectory))) && lastSlash >= 0) {
+ adjustment = module.substring(0, lastSlash);
+ break;
+ }
+ }
+ }
+
+ return adjustment;
+ }
+
+ /**
+ * InheritanceModelMerger
+ */
+ protected static class InheritanceModelMerger extends MavenModelMerger {
+
+ @Override
+ protected String extrapolateChildUrl(String parentUrl, boolean appendPath, Map<Object, Object> context) {
+ Object childDirectory = context.get(CHILD_DIRECTORY);
+ Object childPathAdjustment = context.get(CHILD_PATH_ADJUSTMENT);
+
+ boolean isBlankParentUrl = true;
+
+ if (parentUrl != null) {
+ for (int i = 0; i < parentUrl.length(); i++) {
+ if (!Character.isWhitespace(parentUrl.charAt(i))) {
+ isBlankParentUrl = false;
+ }
+ }
+ }
+
+ if (isBlankParentUrl || childDirectory == null || childPathAdjustment == null || !appendPath) {
+ return parentUrl;
+ }
+
+ // append childPathAdjustment and childDirectory to parent url
+ return appendPath(parentUrl, childDirectory.toString(), childPathAdjustment.toString());
+ }
+
+ private String appendPath(String parentUrl, String childPath, String pathAdjustment) {
+ StringBuilder url = new StringBuilder(parentUrl.length()
+ + pathAdjustment.length()
+ + childPath.length()
+ + (pathAdjustment.isEmpty() ? 1 : 2));
+
+ url.append(parentUrl);
+ concatPath(url, pathAdjustment);
+ concatPath(url, childPath);
+
+ return url.toString();
+ }
+
+ private void concatPath(StringBuilder url, String path) {
+ if (!path.isEmpty()) {
+ boolean initialUrlEndsWithSlash = url.charAt(url.length() - 1) == '/';
+ boolean pathStartsWithSlash = path.charAt(0) == '/';
+
+ if (pathStartsWithSlash) {
+ if (initialUrlEndsWithSlash) {
+ // 1 extra '/' to remove
+ url.setLength(url.length() - 1);
+ }
+ } else if (!initialUrlEndsWithSlash) {
+ // add missing '/' between url and path
+ url.append('/');
+ }
+
+ url.append(path);
+
+ // ensure resulting url ends with slash if initial url was
+ if (initialUrlEndsWithSlash && !path.endsWith("/")) {
+ url.append('/');
+ }
+ }
+ }
+
+ @Override
+ protected void mergeModelBase_Properties(
+ ModelBase.Builder builder,
+ ModelBase target,
+ ModelBase source,
+ boolean sourceDominant,
+ Map<Object, Object> context) {
+ Map<String, String> merged = new HashMap<>();
+ if (sourceDominant) {
+ merged.putAll(target.getProperties());
+ putAll(merged, source.getProperties(), CHILD_DIRECTORY_PROPERTY);
+ } else {
+ putAll(merged, source.getProperties(), CHILD_DIRECTORY_PROPERTY);
+ merged.putAll(target.getProperties());
+ }
+ builder.properties(merged);
+ builder.location(
+ "properties",
+ InputLocation.merge(
+ target.getLocation("properties"), source.getLocation("properties"), sourceDominant));
+ }
+
+ private void putAll(Map<String, String> s, Map<String, String> t, Object excludeKey) {
+ for (Map.Entry<String, String> e : t.entrySet()) {
+ if (!e.getKey().equals(excludeKey)) {
+ s.put(e.getKey(), e.getValue());
+ }
+ }
+ }
+
+ @Override
+ protected void mergePluginContainer_Plugins(
+ PluginContainer.Builder builder,
+ PluginContainer target,
+ PluginContainer source,
+ boolean sourceDominant,
+ Map<Object, Object> context) {
+ List<Plugin> src = source.getPlugins();
+ if (!src.isEmpty()) {
+ List<Plugin> tgt = target.getPlugins();
+ Map<Object, Plugin> master = new LinkedHashMap<>(src.size() * 2);
+
+ for (Plugin element : src) {
+ if (element.isInherited() || !element.getExecutions().isEmpty()) {
+ // NOTE: Enforce recursive merge to trigger merging/inheritance logic for executions
+ Plugin plugin = Plugin.newInstance(false);
+ plugin = mergePlugin(plugin, element, sourceDominant, context);
+
+ Object key = getPluginKey().apply(plugin);
+
+ master.put(key, plugin);
+ }
+ }
+
+ Map<Object, List<Plugin>> predecessors = new LinkedHashMap<>();
+ List<Plugin> pending = new ArrayList<>();
+ for (Plugin element : tgt) {
+ Object key = getPluginKey().apply(element);
+ Plugin existing = master.get(key);
+ if (existing != null) {
+ element = mergePlugin(element, existing, sourceDominant, context);
+
+ master.put(key, element);
+
+ if (!pending.isEmpty()) {
+ predecessors.put(key, pending);
+ pending = new ArrayList<>();
+ }
+ } else {
+ pending.add(element);
+ }
+ }
+
+ List<Plugin> result = new ArrayList<>(src.size() + tgt.size());
+ for (Map.Entry<Object, Plugin> entry : master.entrySet()) {
+ List<Plugin> pre = predecessors.get(entry.getKey());
+ if (pre != null) {
+ result.addAll(pre);
+ }
+ result.add(entry.getValue());
+ }
+ result.addAll(pending);
+
+ builder.plugins(result);
+ }
+ }
+
+ @Override
+ protected Plugin mergePlugin(
+ Plugin target, Plugin source, boolean sourceDominant, Map<Object, Object> context) {
+ Plugin.Builder builder = Plugin.newBuilder(target);
+ if (source.isInherited()) {
+ mergeConfigurationContainer(builder, target, source, sourceDominant, context);
+ }
+ mergePlugin_GroupId(builder, target, source, sourceDominant, context);
+ mergePlugin_ArtifactId(builder, target, source, sourceDominant, context);
+ mergePlugin_Version(builder, target, source, sourceDominant, context);
+ mergePlugin_Extensions(builder, target, source, sourceDominant, context);
+ mergePlugin_Executions(builder, target, source, sourceDominant, context);
+ mergePlugin_Dependencies(builder, target, source, sourceDominant, context);
+ return builder.build();
+ }
+
+ @Override
+ protected void mergeReporting_Plugins(
+ Reporting.Builder builder,
+ Reporting target,
+ Reporting source,
+ boolean sourceDominant,
+ Map<Object, Object> context) {
+ List<ReportPlugin> src = source.getPlugins();
+ if (!src.isEmpty()) {
+ List<ReportPlugin> tgt = target.getPlugins();
+ Map<Object, ReportPlugin> merged = new LinkedHashMap<>((src.size() + tgt.size()) * 2);
+
+ for (ReportPlugin element : src) {
+ if (element.isInherited()) {
+ // NOTE: Enforce recursive merge to trigger merging/inheritance logic for executions as well
+ ReportPlugin plugin = ReportPlugin.newInstance(false);
+ plugin = mergeReportPlugin(plugin, element, sourceDominant, context);
+
+ merged.put(getReportPluginKey().apply(element), plugin);
+ }
+ }
+
+ for (ReportPlugin element : tgt) {
+ Object key = getReportPluginKey().apply(element);
+ ReportPlugin existing = merged.get(key);
+ if (existing != null) {
+ element = mergeReportPlugin(element, existing, sourceDominant, context);
+ }
+ merged.put(key, element);
+ }
+
+ builder.plugins(merged.values());
+ }
+ }
+ }
+}
diff --git a/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultLifecycleBindingsInjector.java
similarity index 57%
copy from maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java
copy to maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultLifecycleBindingsInjector.java
index ce53874427..3418ef1d1b 100644
--- a/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultLifecycleBindingsInjector.java
@@ -16,33 +16,34 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.model.plugin;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
+package org.apache.maven.internal.impl.model;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.maven.api.Packaging;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
import org.apache.maven.api.model.Build;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.model.Plugin;
import org.apache.maven.api.model.PluginContainer;
import org.apache.maven.api.model.PluginExecution;
import org.apache.maven.api.model.PluginManagement;
-import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer;
-import org.apache.maven.model.building.ModelBuildingRequest;
-import org.apache.maven.model.building.ModelProblem.Severity;
-import org.apache.maven.model.building.ModelProblem.Version;
-import org.apache.maven.model.building.ModelProblemCollector;
-import org.apache.maven.model.building.ModelProblemCollectorRequest;
-import org.apache.maven.model.merge.MavenModelMerger;
+import org.apache.maven.api.services.BuilderProblem.Severity;
+import org.apache.maven.api.services.LifecycleRegistry;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblem.Version;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.services.PackagingRegistry;
+import org.apache.maven.api.services.model.*;
/**
* Handles injection of plugin executions induced by the lifecycle bindings for a packaging.
@@ -54,35 +55,71 @@ public class DefaultLifecycleBindingsInjector implements LifecycleBindingsInject
private final LifecycleBindingsMerger merger = new LifecycleBindingsMerger();
- private final LifeCyclePluginAnalyzer lifecycle;
+ private final LifecycleRegistry lifecycleRegistry;
+ private final PackagingRegistry packagingRegistry;
@Inject
- public DefaultLifecycleBindingsInjector(LifeCyclePluginAnalyzer lifecycle) {
- this.lifecycle = lifecycle;
+ public DefaultLifecycleBindingsInjector(LifecycleRegistry lifecycleRegistry, PackagingRegistry packagingRegistry) {
+ this.lifecycleRegistry = lifecycleRegistry;
+ this.packagingRegistry = packagingRegistry;
}
- public void injectLifecycleBindings(
- org.apache.maven.model.Model model, ModelBuildingRequest request, ModelProblemCollector problems) {
- String packaging = model.getPackaging();
-
- Collection<org.apache.maven.model.Plugin> defaultPlugins =
- lifecycle.getPluginsBoundByDefaultToAllLifecycles(packaging);
-
- if (defaultPlugins == null) {
- problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
- .setMessage("Unknown packaging: " + packaging)
- .setLocation(model.getLocation("packaging")));
- } else if (!defaultPlugins.isEmpty()) {
- List<Plugin> plugins = defaultPlugins.stream()
- .map(org.apache.maven.model.Plugin::getDelegate)
- .collect(Collectors.toList());
+ public Model injectLifecycleBindings(Model model, ModelBuilderRequest request, ModelProblemCollector problems) {
+ String packagingId = model.getPackaging();
+ Packaging packaging = packagingRegistry.lookup(packagingId).orElse(null);
+ if (packaging == null) {
+ problems.add(
+ Severity.ERROR, Version.BASE, "Unknown packaging: " + packagingId, model.getLocation("packaging"));
+ return model;
+ } else {
+ Map<String, PluginContainer> plugins = new HashMap<>(packaging.plugins());
+ lifecycleRegistry.stream()
+ .filter(lf -> !plugins.containsKey(lf.id()))
+ .forEach(lf -> plugins.put(
+ lf.id(),
+ PluginContainer.newBuilder()
+ .plugins(lf.phases().stream()
+ .flatMap(phase -> phase.plugins().stream())
+ .toList())
+ .build()));
+ Map<Plugin, Plugin> allPlugins = new LinkedHashMap<>();
+ plugins.values().stream().flatMap(pc -> pc.getPlugins().stream()).forEach(p -> addPlugin(allPlugins, p));
Model lifecycleModel = Model.newBuilder()
- .build(Build.newBuilder().plugins(plugins).build())
+ .build(Build.newBuilder().plugins(allPlugins.values()).build())
.build();
- model.update(merger.merge(model.getDelegate(), lifecycleModel));
+ return merger.merge(model, lifecycleModel);
+ }
+ }
+
+ private void addPlugin(Map<Plugin, Plugin> plugins, Plugin plugin) {
+ Plugin cur = plugins.putIfAbsent(plugin, plugin);
+ if (cur != null) {
+ Map<String, PluginExecution> execs = new LinkedHashMap<>();
+ cur.getExecutions().forEach(e -> execs.put(e.getId(), e));
+ plugin.getExecutions().forEach(e -> {
+ int i = 0;
+ String id = e.getId();
+ while (execs.putIfAbsent(id, e.withId(id)) != null) {
+ id = e.getId() + "-" + (++i);
+ }
+ });
+ Plugin merged = cur.withExecutions(execs.values());
+ plugins.put(merged, merged);
}
}
+ private static String getExecutionId(Plugin plugin, String goal) {
+ Set<String> existingIds = plugin != null
+ ? plugin.getExecutions().stream().map(PluginExecution::getId).collect(Collectors.toSet())
+ : Set.of();
+ String base = "default-" + goal;
+ String id = base;
+ for (int index = 1; existingIds.contains(id); index++) {
+ id = base + '-' + index;
+ }
+ return id;
+ }
+
/**
* The domain-specific model merger for lifecycle bindings
*/
@@ -96,10 +133,10 @@ public class DefaultLifecycleBindingsInjector implements LifecycleBindingsInject
targetBuild = Build.newInstance();
}
- Map<Object, Object> context = Collections.singletonMap(
- PLUGIN_MANAGEMENT, target.getBuild().getPluginManagement());
+ Map<Object, Object> context =
+ Collections.singletonMap(PLUGIN_MANAGEMENT, targetBuild.getPluginManagement());
- Build.Builder builder = Build.newBuilder(target.getBuild());
+ Build.Builder builder = Build.newBuilder(targetBuild);
mergePluginContainer_Plugins(builder, targetBuild, source.getBuild(), false, context);
return target.withBuild(builder.build());
@@ -171,6 +208,5 @@ public class DefaultLifecycleBindingsInjector implements LifecycleBindingsInject
}
}
// mergePluginExecution_Priority( builder, target, source, sourceDominant, context );
-
}
}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java
new file mode 100644
index 0000000000..e10a05887f
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java
@@ -0,0 +1,1410 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+import org.apache.maven.api.VersionRange;
+import org.apache.maven.api.annotations.Nullable;
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.feature.Features;
+import org.apache.maven.api.model.Activation;
+import org.apache.maven.api.model.ActivationFile;
+import org.apache.maven.api.model.Build;
+import org.apache.maven.api.model.Dependency;
+import org.apache.maven.api.model.DependencyManagement;
+import org.apache.maven.api.model.Exclusion;
+import org.apache.maven.api.model.InputLocation;
+import org.apache.maven.api.model.InputSource;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Parent;
+import org.apache.maven.api.model.Plugin;
+import org.apache.maven.api.model.PluginManagement;
+import org.apache.maven.api.model.Profile;
+import org.apache.maven.api.services.BuilderProblem.Severity;
+import org.apache.maven.api.services.ModelBuilder;
+import org.apache.maven.api.services.ModelBuilderException;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelBuilderResult;
+import org.apache.maven.api.services.ModelProblem;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.services.ModelResolver;
+import org.apache.maven.api.services.ModelResolverException;
+import org.apache.maven.api.services.ModelSource;
+import org.apache.maven.api.services.ModelTransformer;
+import org.apache.maven.api.services.ModelTransformerContext;
+import org.apache.maven.api.services.ModelTransformerContextBuilder;
+import org.apache.maven.api.services.ModelTransformerException;
+import org.apache.maven.api.services.Source;
+import org.apache.maven.api.services.SuperPomProvider;
+import org.apache.maven.api.services.VersionParserException;
+import org.apache.maven.api.services.model.*;
+import org.apache.maven.api.services.model.ModelCache;
+import org.apache.maven.api.services.xml.XmlReaderException;
+import org.apache.maven.api.services.xml.XmlReaderRequest;
+import org.apache.maven.internal.impl.InternalSession;
+import org.apache.maven.internal.impl.resolver.DefaultModelCache;
+import org.apache.maven.internal.impl.resolver.DefaultModelResolver;
+import org.codehaus.plexus.interpolation.InterpolationException;
+import org.codehaus.plexus.interpolation.MapBasedValueSource;
+import org.codehaus.plexus.interpolation.StringSearchInterpolator;
+import org.eclipse.aether.impl.RemoteRepositoryManager;
+
+/**
+ */
+@Named
+@Singleton
+public class DefaultModelBuilder implements ModelBuilder {
+
+ private static final String RAW = "raw";
+ private static final String FILE = "file";
+ private static final String IMPORT = "import";
+
+ private final ModelProcessor modelProcessor;
+ private final ModelValidator modelValidator;
+ private final ModelNormalizer modelNormalizer;
+ private final ModelInterpolator modelInterpolator;
+ private final ModelPathTranslator modelPathTranslator;
+ private final ModelUrlNormalizer modelUrlNormalizer;
+ private final SuperPomProvider superPomProvider;
+ private final InheritanceAssembler inheritanceAssembler;
+ private final ProfileSelector profileSelector;
+ private final ProfileInjector profileInjector;
+ private final PluginManagementInjector pluginManagementInjector;
+ private final DependencyManagementInjector dependencyManagementInjector;
+ private final DependencyManagementImporter dependencyManagementImporter;
+ private final LifecycleBindingsInjector lifecycleBindingsInjector;
+ private final PluginConfigurationExpander pluginConfigurationExpander;
+ private final ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator;
+ private final ModelTransformer transformer;
+ private final ModelVersionParser versionParser;
+ private final RemoteRepositoryManager remoteRepositoryManager;
+
+ @SuppressWarnings("checkstyle:ParameterNumber")
+ @Inject
+ public DefaultModelBuilder(
+ ModelProcessor modelProcessor,
+ ModelValidator modelValidator,
+ ModelNormalizer modelNormalizer,
+ ModelInterpolator modelInterpolator,
+ ModelPathTranslator modelPathTranslator,
+ ModelUrlNormalizer modelUrlNormalizer,
+ SuperPomProvider superPomProvider,
+ InheritanceAssembler inheritanceAssembler,
+ ProfileSelector profileSelector,
+ ProfileInjector profileInjector,
+ PluginManagementInjector pluginManagementInjector,
+ DependencyManagementInjector dependencyManagementInjector,
+ DependencyManagementImporter dependencyManagementImporter,
+ @Nullable LifecycleBindingsInjector lifecycleBindingsInjector,
+ PluginConfigurationExpander pluginConfigurationExpander,
+ ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator,
+ ModelTransformer transformer,
+ ModelVersionParser versionParser,
+ RemoteRepositoryManager remoteRepositoryManager) {
+ this.modelProcessor = modelProcessor;
+ this.modelValidator = modelValidator;
+ this.modelNormalizer = modelNormalizer;
+ this.modelInterpolator = modelInterpolator;
+ this.modelPathTranslator = modelPathTranslator;
+ this.modelUrlNormalizer = modelUrlNormalizer;
+ this.superPomProvider = superPomProvider;
+ this.inheritanceAssembler = inheritanceAssembler;
+ this.profileSelector = profileSelector;
+ this.profileInjector = profileInjector;
+ this.pluginManagementInjector = pluginManagementInjector;
+ this.dependencyManagementInjector = dependencyManagementInjector;
+ this.dependencyManagementImporter = dependencyManagementImporter;
+ this.lifecycleBindingsInjector = lifecycleBindingsInjector;
+ this.pluginConfigurationExpander = pluginConfigurationExpander;
+ this.profileActivationFilePathInterpolator = profileActivationFilePathInterpolator;
+ this.transformer = transformer;
+ this.versionParser = versionParser;
+ this.remoteRepositoryManager = remoteRepositoryManager;
+ }
+
+ @Override
+ public ModelTransformerContextBuilder newTransformerContextBuilder() {
+ return new DefaultModelTransformerContextBuilder(this);
+ }
+
+ @Override
+ public ModelBuilderResult build(ModelBuilderRequest request) throws ModelBuilderException {
+ if (request.getInterimResult() != null) {
+ return build(request, request.getInterimResult(), new LinkedHashSet<>());
+ } else {
+ return build(request, new LinkedHashSet<>());
+ }
+ }
+
+ protected ModelBuilderResult build(ModelBuilderRequest request, Collection<String> importIds)
+ throws ModelBuilderException {
+ // phase 1
+ DefaultModelBuilderResult result = new DefaultModelBuilderResult();
+
+ DefaultModelProblemCollector problems = new DefaultModelProblemCollector(result);
+
+ // read and validate raw model
+ Model fileModel = readFileModel(request, problems);
+ result.setFileModel(fileModel);
+
+ Model activatedFileModel = activateFileModel(fileModel, request, result, problems);
+ result.setActivatedFileModel(activatedFileModel);
+
+ if (!request.isTwoPhaseBuilding()) {
+ return build(request, result, importIds);
+ } else if (hasModelErrors(problems)) {
+ throw problems.newModelBuilderException();
+ }
+
+ return result;
+ }
+
+ private Model activateFileModel(
+ Model inputModel,
+ ModelBuilderRequest request,
+ DefaultModelBuilderResult result,
+ DefaultModelProblemCollector problems)
+ throws ModelBuilderException {
+ problems.setRootModel(inputModel);
+
+ // profile activation
+ DefaultProfileActivationContext profileActivationContext = getProfileActivationContext(request, inputModel);
+
+ problems.setSource("(external profiles)");
+ List<Profile> activeExternalProfiles =
+ profileSelector.getActiveProfiles(request.getProfiles(), profileActivationContext, problems);
+
+ result.setActiveExternalProfiles(activeExternalProfiles);
+
+ if (!activeExternalProfiles.isEmpty()) {
+ Properties profileProps = new Properties();
+ for (Profile profile : activeExternalProfiles) {
+ profileProps.putAll(profile.getProperties());
+ }
+ profileProps.putAll(profileActivationContext.getUserProperties());
+ profileActivationContext.setUserProperties(profileProps);
+ }
+
+ profileActivationContext.setProjectProperties(inputModel.getProperties());
+ problems.setSource(inputModel);
+ List<Profile> activePomProfiles =
+ profileSelector.getActiveProfiles(inputModel.getProfiles(), profileActivationContext, problems);
+
+ // model normalization
+ problems.setSource(inputModel);
+ inputModel = modelNormalizer.mergeDuplicates(inputModel, request, problems);
+
+ Map<String, Activation> interpolatedActivations = getProfileActivations(inputModel);
+ inputModel = injectProfileActivations(inputModel, interpolatedActivations);
+
+ // profile injection
+ inputModel = profileInjector.injectProfiles(inputModel, activePomProfiles, request, problems);
+ inputModel = profileInjector.injectProfiles(inputModel, activeExternalProfiles, request, problems);
+
+ return inputModel;
+ }
+
+ @SuppressWarnings("checkstyle:methodlength")
+ private Model readEffectiveModel(
+ final ModelBuilderRequest request,
+ final DefaultModelBuilderResult result,
+ DefaultModelProblemCollector problems)
+ throws ModelBuilderException {
+ Model inputModel = readRawModel(request, problems);
+ if (problems.hasFatalErrors()) {
+ throw problems.newModelBuilderException();
+ }
+
+ inputModel = activateFileModel(inputModel, request, result, problems);
+
+ problems.setRootModel(inputModel);
+
+ ModelData resultData = new ModelData(request.getSource(), inputModel);
+ String superModelVersion = inputModel.getModelVersion() != null ? inputModel.getModelVersion() : "4.0.0";
+ if (!VALID_MODEL_VERSIONS.contains(superModelVersion)) {
+ // Maven 3.x is always using 4.0.0 version to load the supermodel, so
+ // do the same when loading a dependency. The model validator will also
+ // check that field later.
+ superModelVersion = "4.0.0";
+ }
+ ModelData superData = new ModelData(null, getSuperModel(superModelVersion));
+
+ // profile activation
+ DefaultProfileActivationContext profileActivationContext = getProfileActivationContext(request, inputModel);
+
+ List<Profile> activeExternalProfiles = result.getActiveExternalProfiles();
+
+ if (!activeExternalProfiles.isEmpty()) {
+ Properties profileProps = new Properties();
+ for (Profile profile : activeExternalProfiles) {
+ profileProps.putAll(profile.getProperties());
+ }
+ profileProps.putAll(profileActivationContext.getUserProperties());
+ profileActivationContext.setUserProperties(profileProps);
+ }
+
+ Collection<String> parentIds = new LinkedHashSet<>();
+
+ List<Model> lineage = new ArrayList<>();
+
+ for (ModelData currentData = resultData; ; ) {
+ String modelId = currentData.id();
+ result.addModelId(modelId);
+
+ Model model = currentData.model();
+ result.setRawModel(modelId, model);
+ problems.setSource(model);
+
+ // model normalization
+ model = modelNormalizer.mergeDuplicates(model, request, problems);
+
+ // profile activation
+ profileActivationContext.setProjectProperties(model.getProperties());
+
+ List<Profile> interpolatedProfiles =
+ interpolateActivations(model.getProfiles(), profileActivationContext, problems);
+
+ // profile injection
+ List<Profile> activePomProfiles =
+ profileSelector.getActiveProfiles(interpolatedProfiles, profileActivationContext, problems);
+ result.setActivePomProfiles(modelId, activePomProfiles);
+ model = profileInjector.injectProfiles(model, activePomProfiles, request, problems);
+ if (currentData == resultData) {
+ model = profileInjector.injectProfiles(model, activeExternalProfiles, request, problems);
+ }
+
+ lineage.add(model);
+
+ if (currentData == superData) {
+ break;
+ }
+
+ // add repositories specified by the current model so that we can resolve the parent
+ configureResolver(getModelResolver(request), model, request, problems, false);
+
+ // we pass a cloned model, so that resolving the parent version does not affect the returned model
+ ModelData parentData = readParent(model, currentData.source(), request, problems);
+
+ if (parentData == null) {
+ currentData = superData;
+ } else if (!parentIds.add(parentData.id())) {
+ StringBuilder message = new StringBuilder("The parents form a cycle: ");
+ for (String parentId : parentIds) {
+ message.append(parentId).append(" -> ");
+ }
+ message.append(parentData.id());
+
+ problems.add(Severity.FATAL, ModelProblem.Version.BASE, message.toString());
+
+ throw problems.newModelBuilderException();
+ } else {
+ currentData = parentData;
+ }
+ }
+
+ Model tmpModel = lineage.get(0);
+
+ // inject interpolated activations
+ List<Profile> interpolated = interpolateActivations(tmpModel.getProfiles(), profileActivationContext, problems);
+ if (interpolated != tmpModel.getProfiles()) {
+ tmpModel = tmpModel.withProfiles(interpolated);
+ }
+
+ // inject external profile into current model
+ tmpModel = profileInjector.injectProfiles(tmpModel, activeExternalProfiles, request, problems);
+
+ lineage.set(0, tmpModel);
+
+ checkPluginVersions(lineage, request, problems);
+
+ // inheritance assembly
+ Model resultModel = assembleInheritance(lineage, request, problems);
+
+ // consider caching inherited model
+
+ problems.setSource(resultModel);
+ problems.setRootModel(resultModel);
+
+ // model interpolation
+ resultModel = interpolateModel(resultModel, request, problems);
+
+ // url normalization
+ resultModel = modelUrlNormalizer.normalize(resultModel, request);
+
+ result.setEffectiveModel(resultModel);
+
+ // Now the fully interpolated model is available: reconfigure the resolver
+ configureResolver(getModelResolver(request), resultModel, request, problems, true);
+
+ return resultModel;
+ }
+
+ private List<Profile> interpolateActivations(
+ List<Profile> profiles, DefaultProfileActivationContext context, DefaultModelProblemCollector problems) {
+ List<Profile> newProfiles = null;
+ for (int index = 0; index < profiles.size(); index++) {
+ Profile profile = profiles.get(index);
+ Activation activation = profile.getActivation();
+ if (activation != null) {
+ ActivationFile file = activation.getFile();
+ if (file != null) {
+ String oldExists = file.getExists();
+ if (isNotEmpty(oldExists)) {
+ try {
+ String newExists = interpolate(oldExists, context);
+ if (!Objects.equals(oldExists, newExists)) {
+ if (newProfiles == null) {
+ newProfiles = new ArrayList<>(profiles);
+ }
+ newProfiles.set(
+ index, profile.withActivation(activation.withFile(file.withExists(newExists))));
+ }
+ } catch (InterpolationException e) {
+ addInterpolationProblem(problems, file, oldExists, e, "exists");
+ }
+ } else {
+ String oldMissing = file.getMissing();
+ if (isNotEmpty(oldMissing)) {
+ try {
+ String newMissing = interpolate(oldMissing, context);
+ if (!Objects.equals(oldMissing, newMissing)) {
+ if (newProfiles == null) {
+ newProfiles = new ArrayList<>(profiles);
+ }
+ newProfiles.set(
+ index,
+ profile.withActivation(activation.withFile(file.withMissing(newMissing))));
+ }
+ } catch (InterpolationException e) {
+ addInterpolationProblem(problems, file, oldMissing, e, "missing");
+ }
+ }
+ }
+ }
+ }
+ }
+ return newProfiles != null ? newProfiles : profiles;
+ }
+
+ private static void addInterpolationProblem(
+ DefaultModelProblemCollector problems,
+ ActivationFile file,
+ String path,
+ InterpolationException e,
+ String locationKey) {
+ problems.add(
+ Severity.ERROR,
+ ModelProblem.Version.BASE,
+ "Failed to interpolate file location " + path + ": " + e.getMessage(),
+ file.getLocation(locationKey),
+ e);
+ }
+
+ private String interpolate(String path, ProfileActivationContext context) throws InterpolationException {
+ return isNotEmpty(path) ? profileActivationFilePathInterpolator.interpolate(path, context) : path;
+ }
+
+ private static boolean isNotEmpty(String string) {
+ return string != null && !string.isEmpty();
+ }
+
+ public ModelBuilderResult build(final ModelBuilderRequest request, final ModelBuilderResult result)
+ throws ModelBuilderException {
+ return build(request, result, new LinkedHashSet<>());
+ }
+
+ public Model buildRawModel(final ModelBuilderRequest request) throws ModelBuilderException {
+ DefaultModelProblemCollector problems = new DefaultModelProblemCollector(new DefaultModelBuilderResult());
+ Model model = readRawModel(request, problems);
+ if (hasModelErrors(problems)) {
+ throw problems.newModelBuilderException();
+ }
+ return model;
+ }
+
+ private ModelBuilderResult build(
+ ModelBuilderRequest request, final ModelBuilderResult phaseOneResult, Collection<String> importIds)
+ throws ModelBuilderException {
+ if (request.getModelResolver() == null) {
+ ModelResolver resolver = new DefaultModelResolver(
+ remoteRepositoryManager,
+ InternalSession.from(request.getSession())
+ .toRepositories(request.getSession().getRemoteRepositories()));
+ request =
+ ModelBuilderRequest.builder(request).modelResolver(resolver).build();
+ }
+
+ DefaultModelBuilderResult result = asDefaultModelBuilderResult(phaseOneResult);
+
+ DefaultModelProblemCollector problems = new DefaultModelProblemCollector(result);
+
+ // phase 2
+ Model resultModel = readEffectiveModel(request, result, problems);
+ problems.setSource(resultModel);
+ problems.setRootModel(resultModel);
+
+ // model path translation
+ resultModel = modelPathTranslator.alignToBaseDirectory(resultModel, resultModel.getProjectDirectory(), request);
+
+ // plugin management injection
+ resultModel = pluginManagementInjector.injectManagement(resultModel, request, problems);
+
+ resultModel = fireEvent(resultModel, request, problems, ModelBuildingListener::buildExtensionsAssembled);
+
+ if (request.isProcessPlugins()) {
+ if (lifecycleBindingsInjector == null) {
+ throw new IllegalStateException("lifecycle bindings injector is missing");
+ }
+
+ // lifecycle bindings injection
+ resultModel = lifecycleBindingsInjector.injectLifecycleBindings(resultModel, request, problems);
+ }
+
+ // dependency management import
+ resultModel = importDependencyManagement(resultModel, request, problems, importIds);
+
+ // dependency management injection
+ resultModel = dependencyManagementInjector.injectManagement(resultModel, request, problems);
+
+ resultModel = modelNormalizer.injectDefaultValues(resultModel, request, problems);
+
+ if (request.isProcessPlugins()) {
+ // plugins configuration
+ resultModel = pluginConfigurationExpander.expandPluginConfiguration(resultModel, request, problems);
+ }
+
+ result.setEffectiveModel(resultModel);
+
+ // effective model validation
+ modelValidator.validateEffectiveModel(resultModel, request, problems);
+
+ if (hasModelErrors(problems)) {
+ throw problems.newModelBuilderException();
+ }
+
+ return result;
+ }
+
+ private DefaultModelBuilderResult asDefaultModelBuilderResult(ModelBuilderResult phaseOneResult) {
+ if (phaseOneResult instanceof DefaultModelBuilderResult) {
+ return (DefaultModelBuilderResult) phaseOneResult;
+ } else {
+ return new DefaultModelBuilderResult(phaseOneResult);
+ }
+ }
+
+ public Result<? extends Model> buildRawModel(Path pomFile, int validationLevel, boolean locationTracking) {
+ return buildRawModel(pomFile, validationLevel, locationTracking, null);
+ }
+
+ public Result<? extends Model> buildRawModel(
+ Path pomFile, int validationLevel, boolean locationTracking, ModelTransformerContext context) {
+ final ModelBuilderRequest request = ModelBuilderRequest.builder()
+ .validationLevel(validationLevel)
+ .locationTracking(locationTracking)
+ .source(ModelSource.fromPath(pomFile))
+ .build();
+ DefaultModelProblemCollector problems = new DefaultModelProblemCollector(new DefaultModelBuilderResult());
+ try {
+ Model model = readFileModel(request, problems);
+
+ try {
+ if (transformer != null && context != null) {
+ transformer.transform(context, model, pomFile);
+ }
+ } catch (ModelBuilderException e) {
+ problems.add(Severity.FATAL, ModelProblem.Version.V40, null, e);
+ }
+
+ return Result.newResult(model, problems.getProblems());
+ } catch (ModelBuilderException e) {
+ return Result.error(problems.getProblems());
+ }
+ }
+
+ Model readFileModel(ModelBuilderRequest request, DefaultModelProblemCollector problems)
+ throws ModelBuilderException {
+ ModelSource modelSource = request.getSource();
+ Model model =
+ cache(getModelCache(request), modelSource, FILE, () -> doReadFileModel(modelSource, request, problems));
+
+ if (modelSource.getPath() != null) {
+ if (getTransformerContextBuilder(request) instanceof DefaultModelTransformerContextBuilder contextBuilder) {
+ contextBuilder.putSource(getGroupId(model), model.getArtifactId(), modelSource);
+ }
+ }
+
+ return model;
+ }
+
+ @SuppressWarnings("checkstyle:methodlength")
+ private Model doReadFileModel(
+ ModelSource modelSource, ModelBuilderRequest request, DefaultModelProblemCollector problems)
+ throws ModelBuilderException {
+ Model model;
+ problems.setSource(modelSource.getLocation());
+ try {
+ boolean strict = request.getValidationLevel() >= ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_2_0;
+
+ try (InputStream is = modelSource.openStream()) {
+ model = modelProcessor.read(XmlReaderRequest.builder()
+ .strict(strict)
+ .location(modelSource.getLocation())
+ .path(modelSource.getPath())
+ .inputStream(is)
+ .build());
+ } catch (XmlReaderException e) {
+ if (!strict) {
+ throw e;
+ }
+ try (InputStream is = modelSource.openStream()) {
+ model = modelProcessor.read(XmlReaderRequest.builder()
+ .strict(false)
+ .location(modelSource.getLocation())
+ .path(modelSource.getPath())
+ .inputStream(is)
+ .build());
+ } catch (XmlReaderException ne) {
+ // still unreadable even in non-strict mode, rethrow original error
+ throw e;
+ }
+
+ Severity severity = request.isProjectBuild() ? Severity.ERROR : Severity.WARNING;
+ problems.add(
+ severity,
+ ModelProblem.Version.V20,
+ "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage(),
+ e);
+ }
+
+ InputLocation loc = model.getLocation("");
+ InputSource v4src = loc != null ? loc.getSource() : null;
+ if (v4src != null) {
+ try {
+ Field field = InputSource.class.getDeclaredField("modelId");
+ field.setAccessible(true);
+ field.set(v4src, ModelProblemUtils.toId(model));
+ } catch (Throwable t) {
+ // TODO: use a lazy source ?
+ throw new IllegalStateException("Unable to set modelId on InputSource", t);
+ }
+ }
+ } catch (XmlReaderException e) {
+ problems.add(
+ Severity.FATAL,
+ ModelProblem.Version.BASE,
+ "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(),
+ e);
+ throw problems.newModelBuilderException();
+ } catch (IOException e) {
+ String msg = e.getMessage();
+ if (msg == null || msg.isEmpty()) {
+ // NOTE: There's java.nio.charset.MalformedInputException and sun.io.MalformedInputException
+ if (e.getClass().getName().endsWith("MalformedInputException")) {
+ msg = "Some input bytes do not match the file encoding.";
+ } else {
+ msg = e.getClass().getSimpleName();
+ }
+ }
+ problems.add(
+ Severity.FATAL,
+ ModelProblem.Version.BASE,
+ "Non-readable POM " + modelSource.getLocation() + ": " + msg,
+ e);
+ throw problems.newModelBuilderException();
+ }
+
+ if (modelSource.getPath() != null) {
+ model = model.withPomFile(modelSource.getPath());
+ }
+
+ problems.setSource(model);
+ modelValidator.validateFileModel(model, request, problems);
+ if (hasFatalErrors(problems)) {
+ throw problems.newModelBuilderException();
+ }
+
+ return model;
+ }
+
+ Model readRawModel(ModelBuilderRequest request, DefaultModelProblemCollector problems)
+ throws ModelBuilderException {
+ ModelSource modelSource = request.getSource();
+
+ ModelData modelData =
+ cache(getModelCache(request), modelSource, RAW, () -> doReadRawModel(modelSource, request, problems));
+
+ return modelData.model();
+ }
+
+ private ModelData doReadRawModel(
+ ModelSource modelSource, ModelBuilderRequest request, DefaultModelProblemCollector problems)
+ throws ModelBuilderException {
+ Model rawModel = readFileModel(request, problems);
+ if (Features.buildConsumer(request.getUserProperties()) && modelSource.getPath() != null) {
+ Path pomFile = modelSource.getPath();
+
+ try {
+ ModelTransformerContextBuilder transformerContextBuilder = getTransformerContextBuilder(request);
+ if (transformerContextBuilder != null) {
+ ModelTransformerContext context = transformerContextBuilder.initialize(request, problems);
+ rawModel = this.transformer.transform(context, rawModel, pomFile);
+ }
+ } catch (ModelTransformerException e) {
+ problems.add(Severity.FATAL, ModelProblem.Version.V40, null, e);
+ }
+ }
+
+ modelValidator.validateRawModel(rawModel, request, problems);
+
+ if (hasFatalErrors(problems)) {
+ throw problems.newModelBuilderException();
+ }
+
+ return new ModelData(modelSource, rawModel);
+ }
+
+ static String getGroupId(Model model) {
+ String groupId = model.getGroupId();
+ if (groupId == null && model.getParent() != null) {
+ groupId = model.getParent().getGroupId();
+ }
+ return groupId;
+ }
+
+ private String getVersion(Model model) {
+ String version = model.getVersion();
+ if (version == null && model.getParent() != null) {
+ version = model.getParent().getVersion();
+ }
+ return version;
+ }
+
+ private DefaultProfileActivationContext getProfileActivationContext(ModelBuilderRequest request, Model model) {
+ DefaultProfileActivationContext context = new DefaultProfileActivationContext();
+
+ context.setActiveProfileIds(request.getActiveProfileIds());
+ context.setInactiveProfileIds(request.getInactiveProfileIds());
+ context.setSystemProperties(request.getSystemProperties());
+ // enrich user properties with project packaging
+ Map<String, String> userProperties = new HashMap<>(request.getUserProperties());
+ if (!userProperties.containsKey(ProfileActivationContext.PROPERTY_NAME_PACKAGING)) {
+ userProperties.put(ProfileActivationContext.PROPERTY_NAME_PACKAGING, model.getPackaging());
+ }
+ context.setUserProperties(userProperties);
+ context.setProjectDirectory(model.getProjectDirectory());
+
+ return context;
+ }
+
+ private void configureResolver(
+ ModelResolver modelResolver,
+ Model model,
+ ModelBuilderRequest request,
+ DefaultModelProblemCollector problems,
+ boolean replaceRepositories) {
+ model.getRepositories().forEach(r -> modelResolver.addRepository(request.getSession(), r, replaceRepositories));
+ }
+
+ private void checkPluginVersions(List<Model> lineage, ModelBuilderRequest request, ModelProblemCollector problems) {
+ if (request.getValidationLevel() < ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_2_0) {
+ return;
+ }
+
+ Map<String, Plugin> plugins = new HashMap<>();
+ Map<String, String> versions = new HashMap<>();
+ Map<String, String> managedVersions = new HashMap<>();
+
+ for (int i = lineage.size() - 1; i >= 0; i--) {
+ Model model = lineage.get(i);
+ Build build = model.getBuild();
+ if (build != null) {
+ for (Plugin plugin : build.getPlugins()) {
+ String key = plugin.getKey();
+ if (versions.get(key) == null) {
+ versions.put(key, plugin.getVersion());
+ plugins.put(key, plugin);
+ }
+ }
+ PluginManagement mgmt = build.getPluginManagement();
+ if (mgmt != null) {
+ for (Plugin plugin : mgmt.getPlugins()) {
+ String key = plugin.getKey();
+ managedVersions.computeIfAbsent(key, k -> plugin.getVersion());
+ }
+ }
+ }
+ }
+
+ for (String key : versions.keySet()) {
+ if (versions.get(key) == null && managedVersions.get(key) == null) {
+ InputLocation location = plugins.get(key).getLocation("");
+ problems.add(
+ Severity.WARNING,
+ ModelProblem.Version.V20,
+ "'build.plugins.plugin.version' for " + key + " is missing.",
+ location);
+ }
+ }
+ }
+
+ private Model assembleInheritance(
+ List<Model> lineage, ModelBuilderRequest request, ModelProblemCollector problems) {
+ Model parent = lineage.get(lineage.size() - 1);
+ for (int i = lineage.size() - 2; i >= 0; i--) {
+ Model child = lineage.get(i);
+ parent = inheritanceAssembler.assembleModelInheritance(child, parent, request, problems);
+ }
+ return parent;
+ }
+
+ private Map<String, Activation> getProfileActivations(Model model) {
+ return model.getProfiles().stream()
+ .filter(p -> p.getActivation() != null)
+ .collect(Collectors.toMap(Profile::getId, Profile::getActivation));
+ }
+
+ private Model injectProfileActivations(Model model, Map<String, Activation> activations) {
+ List<Profile> profiles = new ArrayList<>();
+ boolean modified = false;
+ for (Profile profile : model.getProfiles()) {
+ Activation activation = profile.getActivation();
+ if (activation != null) {
+ // restore activation
+ profile = profile.withActivation(activations.get(profile.getId()));
+ modified = true;
+ }
+ profiles.add(profile);
+ }
+ return modified ? model.withProfiles(profiles) : model;
+ }
+
+ private Model interpolateModel(Model model, ModelBuilderRequest request, ModelProblemCollector problems) {
+ Model interpolatedModel =
+ modelInterpolator.interpolateModel(model, model.getProjectDirectory(), request, problems);
+ if (interpolatedModel.getParent() != null) {
+ StringSearchInterpolator ssi = new StringSearchInterpolator();
+ ssi.addValueSource(new MapBasedValueSource(request.getSession().getUserProperties()));
+ ssi.addValueSource(new MapBasedValueSource(model.getProperties()));
+ ssi.addValueSource(new MapBasedValueSource(request.getSession().getSystemProperties()));
+ try {
+ String interpolated =
+ ssi.interpolate(interpolatedModel.getParent().getVersion());
+ interpolatedModel = interpolatedModel.withParent(
+ interpolatedModel.getParent().withVersion(interpolated));
+ } catch (Exception e) {
+ problems.add(
+ Severity.ERROR,
+ ModelProblem.Version.BASE,
+ "Failed to interpolate field: "
+ + interpolatedModel.getParent().getVersion()
+ + " on class: ",
+ e);
+ }
+ }
+ interpolatedModel = interpolatedModel.withPomFile(model.getPomFile());
+ return interpolatedModel;
+ }
+
+ private ModelData readParent(
+ Model childModel,
+ ModelSource childSource,
+ ModelBuilderRequest request,
+ DefaultModelProblemCollector problems)
+ throws ModelBuilderException {
+ ModelData parentData = null;
+
+ Parent parent = childModel.getParent();
+ if (parent != null) {
+ parentData = readParentLocally(childModel, childSource, request, problems);
+ if (parentData == null) {
+ parentData = readParentExternally(childModel, request, problems);
+ }
+
+ Model parentModel = parentData.model();
+ if (!"pom".equals(parentModel.getPackaging())) {
+ problems.add(
+ Severity.ERROR,
+ ModelProblem.Version.BASE,
+ "Invalid packaging for parent POM " + ModelProblemUtils.toSourceHint(parentModel)
+ + ", must be \"pom\" but is \"" + parentModel.getPackaging() + "\"",
+ parentModel.getLocation("packaging"));
+ }
+ }
+
+ return parentData;
+ }
+
+ private ModelData readParentLocally(
+ Model childModel,
+ ModelSource childSource,
+ ModelBuilderRequest request,
+ DefaultModelProblemCollector problems)
+ throws ModelBuilderException {
+ final Parent parent = childModel.getParent();
+ final ModelSource candidateSource;
+ final Model candidateModel;
+ final WorkspaceModelResolver resolver = getWorkspaceModelResolver(request);
+ if (resolver == null) {
+ candidateSource = getParentPomFile(childModel, childSource);
+
+ if (candidateSource == null) {
+ return null;
+ }
+
+ ModelBuilderRequest candidateBuildRequest = ModelBuilderRequest.build(request, candidateSource);
+
+ candidateModel = readRawModel(candidateBuildRequest, problems);
+ } else {
+ try {
+ candidateModel =
+ resolver.resolveRawModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
+ } catch (ModelBuilderException e) {
+ problems.add(Severity.FATAL, ModelProblem.Version.BASE, e.getMessage(), parent.getLocation(""), e);
+ throw problems.newModelBuilderException();
+ }
+ if (candidateModel == null) {
+ return null;
+ }
+ candidateSource = ModelSource.fromPath(candidateModel.getPomFile());
+ }
+
+ //
+ // TODO jvz Why isn't all this checking the job of the duty of the workspace resolver, we know that we
+ // have a model that is suitable, yet more checks are done here and the one for the version is problematic
+ // before because with parents as ranges it will never work in this scenario.
+ //
+
+ String groupId = getGroupId(candidateModel);
+ String artifactId = candidateModel.getArtifactId();
+
+ if (groupId == null
+ || !groupId.equals(parent.getGroupId())
+ || artifactId == null
+ || !artifactId.equals(parent.getArtifactId())) {
+ StringBuilder buffer = new StringBuilder(256);
+ buffer.append("'parent.relativePath'");
+ if (childModel != problems.getRootModel()) {
+ buffer.append(" of POM ").append(ModelProblemUtils.toSourceHint(childModel));
+ }
+ buffer.append(" points at ").append(groupId).append(':').append(artifactId);
+ buffer.append(" instead of ").append(parent.getGroupId()).append(':');
+ buffer.append(parent.getArtifactId()).append(", please verify your project structure");
+
+ problems.setSource(childModel);
+ problems.add(Severity.WARNING, ModelProblem.Version.BASE, buffer.toString(), parent.getLocation(""));
+ return null;
+ }
+
+ String version = getVersion(candidateModel);
+ if (version != null && parent.getVersion() != null && !version.equals(parent.getVersion())) {
+ try {
+ VersionRange parentRange = versionParser.parseVersionRange(parent.getVersion());
+ if (!parentRange.contains(versionParser.parseVersion(version))) {
+ // version skew drop back to resolution from the repository
+ return null;
+ }
+
+ // Validate versions aren't inherited when using parent ranges the same way as when read externally.
+ String rawChildModelVersion = childModel.getVersion();
+
+ if (rawChildModelVersion == null) {
+ // Message below is checked for in the MNG-2199 core IT.
+ problems.add(
+ Severity.FATAL,
+ ModelProblem.Version.V31,
+ "Version must be a constant",
+ childModel.getLocation(""));
+
+ } else {
+ if (rawChildVersionReferencesParent(rawChildModelVersion)) {
+ // Message below is checked for in the MNG-2199 core IT.
+ problems.add(
+ Severity.FATAL,
+ ModelProblem.Version.V31,
+ "Version must be a constant",
+ childModel.getLocation("version"));
+ }
+ }
+
+ // MNG-2199: What else to check here ?
+ } catch (VersionParserException e) {
+ // invalid version range, so drop back to resolution from the repository
+ return null;
+ }
+ }
+
+ //
+ // Here we just need to know that a version is fine to use but this validation we can do in our workspace
+ // resolver.
+ //
+
+ /*
+ * if ( version == null || !version.equals( parent.getVersion() ) ) { return null; }
+ */
+
+ return new ModelData(candidateSource, candidateModel);
+ }
+
+ private boolean rawChildVersionReferencesParent(String rawChildModelVersion) {
+ return rawChildModelVersion.equals("${pom.version}")
+ || rawChildModelVersion.equals("${project.version}")
+ || rawChildModelVersion.equals("${pom.parent.version}")
+ || rawChildModelVersion.equals("${project.parent.version}");
+ }
+
+ private ModelSource getParentPomFile(Model childModel, ModelSource source) {
+ String parentPath = childModel.getParent().getRelativePath();
+ if (parentPath == null || parentPath.isEmpty()) {
+ return null;
+ } else {
+ return source.resolve(modelProcessor::locateExistingPom, parentPath);
+ }
+ }
+
+ private ModelData readParentExternally(
+ Model childModel, ModelBuilderRequest request, DefaultModelProblemCollector problems)
+ throws ModelBuilderException {
+ problems.setSource(childModel);
+
+ Parent parent = childModel.getParent();
+
+ String groupId = parent.getGroupId();
+ String artifactId = parent.getArtifactId();
+ String version = parent.getVersion();
+
+ ModelResolver modelResolver = getModelResolver(request);
+ Objects.requireNonNull(
+ modelResolver,
+ String.format(
+ "request.modelResolver cannot be null (parent POM %s and POM %s)",
+ ModelProblemUtils.toId(groupId, artifactId, version),
+ ModelProblemUtils.toSourceHint(childModel)));
+
+ ModelSource modelSource;
+ try {
+ AtomicReference<Parent> modified = new AtomicReference<>();
+ modelSource = modelResolver.resolveModel(request.getSession(), parent, modified);
+ if (modified.get() != null) {
+ parent = modified.get();
+ }
+ } catch (ModelResolverException e) {
+ // Message below is checked for in the MNG-2199 core IT.
+ StringBuilder buffer = new StringBuilder(256);
+ buffer.append("Non-resolvable parent POM");
+ if (!containsCoordinates(e.getMessage(), groupId, artifactId, version)) {
+ buffer.append(' ').append(ModelProblemUtils.toId(groupId, artifactId, version));
+ }
+ if (childModel != problems.getRootModel()) {
+ buffer.append(" for ").append(ModelProblemUtils.toId(childModel));
+ }
+ buffer.append(": ").append(e.getMessage());
+ if (childModel.getProjectDirectory() != null) {
+ if (parent.getRelativePath() == null || parent.getRelativePath().isEmpty()) {
+ buffer.append(" and 'parent.relativePath' points at no local POM");
+ } else {
+ buffer.append(" and 'parent.relativePath' points at wrong local POM");
+ }
+ }
+
+ problems.add(Severity.FATAL, ModelProblem.Version.BASE, buffer.toString(), parent.getLocation(""), e);
+ throw problems.newModelBuilderException();
+ }
+
+ int validationLevel = Math.min(request.getValidationLevel(), ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_2_0);
+ ModelBuilderRequest lenientRequest = ModelBuilderRequest.builder(request)
+ .validationLevel(validationLevel)
+ .projectBuild(false)
+ .source(modelSource)
+ .build();
+
+ Model parentModel = readRawModel(lenientRequest, problems);
+
+ if (!parent.getVersion().equals(version)) {
+ String rawChildModelVersion = childModel.getVersion();
+
+ if (rawChildModelVersion == null) {
+ // Message below is checked for in the MNG-2199 core IT.
+ problems.add(
+ Severity.FATAL,
+ ModelProblem.Version.V31,
+ "Version must be a constant",
+ childModel.getLocation(""));
+
+ } else {
+ if (rawChildVersionReferencesParent(rawChildModelVersion)) {
+ // Message below is checked for in the MNG-2199 core IT.
+ problems.add(
+ Severity.FATAL,
+ ModelProblem.Version.V31,
+ "Version must be a constant",
+ childModel.getLocation("version"));
+ }
+ }
+
+ // MNG-2199: What else to check here ?
+ }
+
+ return new ModelData(modelSource, parentModel);
+ }
+
+ private Model getSuperModel(String modelVersion) {
+ return superPomProvider.getSuperPom(modelVersion);
+ }
+
+ private Model importDependencyManagement(
+ Model model,
+ ModelBuilderRequest request,
+ DefaultModelProblemCollector problems,
+ Collection<String> importIds) {
+ DependencyManagement depMgmt = model.getDependencyManagement();
+
+ if (depMgmt == null) {
+ return model;
+ }
+
+ String importing = model.getGroupId() + ':' + model.getArtifactId() + ':' + model.getVersion();
+
+ importIds.add(importing);
+
+ List<DependencyManagement> importMgmts = null;
+
+ List<Dependency> deps = new ArrayList<>(depMgmt.getDependencies());
+ for (Iterator<Dependency> it = deps.iterator(); it.hasNext(); ) {
+ Dependency dependency = it.next();
+
+ if (!("pom".equals(dependency.getType()) && "import".equals(dependency.getScope()))
+ || "bom".equals(dependency.getType())) {
+ continue;
+ }
+
+ it.remove();
+
+ DependencyManagement importMgmt = loadDependencyManagement(model, request, problems, dependency, importIds);
+
+ if (importMgmt != null) {
+ if (importMgmts == null) {
+ importMgmts = new ArrayList<>();
+ }
+
+ importMgmts.add(importMgmt);
+ }
+ }
+
+ importIds.remove(importing);
+
+ model = model.withDependencyManagement(model.getDependencyManagement().withDependencies(deps));
+
+ return dependencyManagementImporter.importManagement(model, importMgmts, request, problems);
+ }
+
+ private DependencyManagement loadDependencyManagement(
+ Model model,
+ ModelBuilderRequest request,
+ DefaultModelProblemCollector problems,
+ Dependency dependency,
+ Collection<String> importIds) {
+ String groupId = dependency.getGroupId();
+ String artifactId = dependency.getArtifactId();
+ String version = dependency.getVersion();
+
+ if (groupId == null || groupId.isEmpty()) {
+ problems.add(
+ Severity.ERROR,
+ ModelProblem.Version.BASE,
+ "'dependencyManagement.dependencies.dependency.groupId' for " + dependency.getManagementKey()
+ + " is missing.",
+ dependency.getLocation(""));
+ return null;
+ }
+ if (artifactId == null || artifactId.isEmpty()) {
+ problems.add(
+ Severity.ERROR,
+ ModelProblem.Version.BASE,
+ "'dependencyManagement.dependencies.dependency.artifactId' for " + dependency.getManagementKey()
+ + " is missing.",
+ dependency.getLocation(""));
+ return null;
+ }
+ if (version == null || version.isEmpty()) {
+ problems.add(
+ Severity.ERROR,
+ ModelProblem.Version.BASE,
+ "'dependencyManagement.dependencies.dependency.version' for " + dependency.getManagementKey()
+ + " is missing.",
+ dependency.getLocation(""));
+ return null;
+ }
+
+ String imported = groupId + ':' + artifactId + ':' + version;
+
+ if (importIds.contains(imported)) {
+ StringBuilder message =
+ new StringBuilder("The dependencies of type=pom and with scope=import form a cycle: ");
+ for (String modelId : importIds) {
+ message.append(modelId).append(" -> ");
+ }
+ message.append(imported);
+ problems.add(Severity.ERROR, ModelProblem.Version.BASE, message.toString());
+
+ return null;
+ }
+
+ DependencyManagement importMgmt = cache(
+ getModelCache(request),
+ groupId,
+ artifactId,
+ version,
+ IMPORT,
+ () -> doLoadDependencyManagement(
+ model, request, problems, dependency, groupId, artifactId, version, importIds));
+
+ // [MNG-5600] Dependency management import should support exclusions.
+ List<Exclusion> exclusions = dependency.getExclusions();
+ if (importMgmt != null && !exclusions.isEmpty()) {
+ // Dependency excluded from import.
+ List<Dependency> dependencies = importMgmt.getDependencies().stream()
+ .filter(candidate -> exclusions.stream().noneMatch(exclusion -> match(exclusion, candidate)))
+ .map(candidate -> candidate.withExclusions(exclusions))
+ .collect(Collectors.toList());
+ importMgmt = importMgmt.withDependencies(dependencies);
+ }
+
+ return importMgmt;
+ }
+
+ private boolean match(Exclusion exclusion, Dependency candidate) {
+ return match(exclusion.getGroupId(), candidate.getGroupId())
+ && match(exclusion.getArtifactId(), candidate.getArtifactId());
+ }
+
+ private boolean match(String match, String text) {
+ return match.equals("*") || match.equals(text);
+ }
+
+ @SuppressWarnings("checkstyle:parameternumber")
+ private DependencyManagement doLoadDependencyManagement(
+ Model model,
+ ModelBuilderRequest request,
+ DefaultModelProblemCollector problems,
+ Dependency dependency,
+ String groupId,
+ String artifactId,
+ String version,
+ Collection<String> importIds) {
+ DependencyManagement importMgmt;
+ final WorkspaceModelResolver workspaceResolver = getWorkspaceModelResolver(request);
+ final ModelResolver modelResolver = getModelResolver(request);
+ if (workspaceResolver == null && modelResolver == null) {
+ throw new NullPointerException(String.format(
+ "request.workspaceModelResolver and request.modelResolver cannot be null (parent POM %s and POM %s)",
+ ModelProblemUtils.toId(groupId, artifactId, version), ModelProblemUtils.toSourceHint(model)));
+ }
+
+ Model importModel = null;
+ if (workspaceResolver != null) {
+ try {
+ importModel = workspaceResolver.resolveEffectiveModel(groupId, artifactId, version);
+ } catch (ModelBuilderException e) {
+ problems.add(Severity.FATAL, ModelProblem.Version.BASE, null, e);
+ return null;
+ }
+ }
+
+ // no workspace resolver or workspace resolver returned null (i.e. model not in workspace)
+ if (importModel == null) {
+ final ModelSource importSource;
+ try {
+ importSource = modelResolver.resolveModel(request.getSession(), dependency, new AtomicReference<>());
+ } catch (ModelBuilderException e) {
+ StringBuilder buffer = new StringBuilder(256);
+ buffer.append("Non-resolvable import POM");
+ if (!containsCoordinates(e.getMessage(), groupId, artifactId, version)) {
+ buffer.append(' ').append(ModelProblemUtils.toId(groupId, artifactId, version));
+ }
+ buffer.append(": ").append(e.getMessage());
+
+ problems.add(
+ Severity.ERROR, ModelProblem.Version.BASE, buffer.toString(), dependency.getLocation(""), e);
+ return null;
+ }
+
+ Path rootDirectory;
+ try {
+ rootDirectory = request.getSession().getRootDirectory();
+ } catch (IllegalStateException e) {
+ rootDirectory = null;
+ }
+ if (importSource.getPath() != null && rootDirectory != null) {
+ Path sourcePath = importSource.getPath();
+ if (sourcePath.startsWith(rootDirectory)) {
+ problems.add(
+ Severity.WARNING,
+ ModelProblem.Version.BASE,
+ "BOM imports from within reactor should be avoided",
+ dependency.getLocation(""));
+ }
+ }
+
+ final ModelBuilderResult importResult;
+ try {
+ ModelBuilderRequest importRequest = ModelBuilderRequest.builder()
+ .session(request.getSession())
+ .validationLevel(ModelBuilderRequest.VALIDATION_LEVEL_MINIMAL)
+ .systemProperties(request.getSystemProperties())
+ .userProperties(request.getUserProperties())
+ .source(importSource)
+ .modelResolver(modelResolver.newCopy())
+ .twoPhaseBuilding(false)
+ .build();
+ importResult = build(importRequest, importIds);
+ } catch (ModelBuilderException e) {
+ e.getResult().getProblems().forEach(problems::add);
+ return null;
+ }
+
+ importResult.getProblems().forEach(problems::add);
+
+ importModel = importResult.getEffectiveModel();
+ }
+
+ importMgmt = importModel.getDependencyManagement();
+
+ if (importMgmt == null) {
+ importMgmt = DependencyManagement.newInstance();
+ }
+ return importMgmt;
+ }
+
+ private static <T> T cache(
+ ModelCache cache, String groupId, String artifactId, String version, String tag, Callable<T> supplier) {
+ Supplier<T> s = asSupplier(supplier);
+ if (cache == null) {
+ return s.get();
+ } else {
+ return cache.computeIfAbsent(groupId, artifactId, version, tag, s);
+ }
+ }
+
+ private static <T> T cache(ModelCache cache, Source source, String tag, Callable<T> supplier) {
+ Supplier<T> s = asSupplier(supplier);
+ if (cache == null) {
+ return s.get();
+ } else {
+ return cache.computeIfAbsent(source, tag, s);
+ }
+ }
+
+ private static <T> Supplier<T> asSupplier(Callable<T> supplier) {
+ return () -> {
+ try {
+ return supplier.call();
+ } catch (Exception e) {
+ uncheckedThrow(e);
+ return null;
+ }
+ };
+ }
+
+ static <T extends Throwable> void uncheckedThrow(Throwable t) throws T {
+ throw (T) t; // rely on vacuous cast
+ }
+
+ private Model fireEvent(
+ Model model,
+ ModelBuilderRequest request,
+ ModelProblemCollector problems,
+ BiConsumer<ModelBuildingListener, ModelBuildingEvent> catapult) {
+ ModelBuildingListener listener = getModelBuildingListener(request);
+
+ if (listener != null) {
+ AtomicReference<Model> m = new AtomicReference<>(model);
+
+ ModelBuildingEvent event = new DefaultModelBuildingEvent(model, m::set, request, problems);
+
+ catapult.accept(listener, event);
+
+ return m.get();
+ }
+
+ return model;
+ }
+
+ private boolean containsCoordinates(String message, String groupId, String artifactId, String version) {
+ return message != null
+ && (groupId == null || message.contains(groupId))
+ && (artifactId == null || message.contains(artifactId))
+ && (version == null || message.contains(version));
+ }
+
+ protected boolean hasModelErrors(ModelProblemCollector problems) {
+ return problems.hasErrors();
+ }
+
+ protected boolean hasFatalErrors(ModelProblemCollector problems) {
+ return problems.hasFatalErrors();
+ }
+
+ ModelProcessor getModelProcessor() {
+ return modelProcessor;
+ }
+
+ private static ModelCache getModelCache(ModelBuilderRequest request) {
+ return request.isProjectBuild()
+ ? DefaultModelCache.newInstance(
+ InternalSession.from(request.getSession()).getSession())
+ : null;
+ }
+
+ private static ModelBuildingListener getModelBuildingListener(ModelBuilderRequest request) {
+ return (ModelBuildingListener) request.getListener();
+ }
+
+ private static WorkspaceModelResolver getWorkspaceModelResolver(ModelBuilderRequest request) {
+ return null; // request.getWorkspaceModelResolver();
+ }
+
+ private static ModelResolver getModelResolver(ModelBuilderRequest request) {
+ return request.getModelResolver();
+ }
+
+ private static ModelTransformerContextBuilder getTransformerContextBuilder(ModelBuilderRequest request) {
+ return request.getTransformerContextBuilder();
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilderResult.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilderResult.java
new file mode 100644
index 0000000000..e10a7e8642
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilderResult.java
@@ -0,0 +1,222 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Profile;
+import org.apache.maven.api.services.ModelBuilderResult;
+import org.apache.maven.api.services.ModelProblem;
+
+/**
+ * Collects the output of the model builder.
+ *
+ */
+class DefaultModelBuilderResult implements ModelBuilderResult {
+ private Model fileModel;
+ private Model activatedFileModel;
+
+ private Model effectiveModel;
+
+ private List<String> modelIds;
+
+ private Map<String, Model> rawModels;
+
+ private Map<String, List<Profile>> activePomProfiles;
+
+ private List<Profile> activeExternalProfiles;
+
+ private List<ModelProblem> problems;
+
+ DefaultModelBuilderResult() {
+ modelIds = new ArrayList<>();
+ rawModels = new HashMap<>();
+ activePomProfiles = new HashMap<>();
+ activeExternalProfiles = new ArrayList<>();
+ problems = new ArrayList<>();
+ }
+
+ DefaultModelBuilderResult(ModelBuilderResult result) {
+ this();
+ this.activeExternalProfiles.addAll(result.getActiveExternalProfiles());
+ this.effectiveModel = result.getEffectiveModel();
+ this.fileModel = result.getFileModel();
+ this.problems.addAll(result.getProblems());
+
+ for (String modelId : result.getModelIds()) {
+ this.modelIds.add(modelId);
+ this.rawModels.put(modelId, result.getRawModel(modelId).orElseThrow());
+ this.activePomProfiles.put(modelId, result.getActivePomProfiles(modelId));
+ }
+ }
+
+ @Override
+ public Model getFileModel() {
+ return fileModel;
+ }
+
+ public DefaultModelBuilderResult setFileModel(Model fileModel) {
+ this.fileModel = fileModel;
+ return this;
+ }
+
+ public Model getActivatedFileModel() {
+ return activatedFileModel;
+ }
+
+ public DefaultModelBuilderResult setActivatedFileModel(Model activatedFileModel) {
+ this.activatedFileModel = activatedFileModel;
+ return this;
+ }
+
+ @Override
+ public Model getEffectiveModel() {
+ return effectiveModel;
+ }
+
+ public DefaultModelBuilderResult setEffectiveModel(Model model) {
+ this.effectiveModel = model;
+ return this;
+ }
+
+ @Override
+ public List<String> getModelIds() {
+ return modelIds;
+ }
+
+ public DefaultModelBuilderResult addModelId(String modelId) {
+ // Intentionally notNull because Super POM may not contain a modelId
+ Objects.requireNonNull(modelId, "modelId cannot be null");
+
+ modelIds.add(modelId);
+
+ return this;
+ }
+
+ @Override
+ public Model getRawModel() {
+ return rawModels.get(modelIds.get(0));
+ }
+
+ @Override
+ public Optional<Model> getRawModel(String modelId) {
+ return Optional.ofNullable(rawModels.get(modelId));
+ }
+
+ public DefaultModelBuilderResult setRawModel(String modelId, Model rawModel) {
+ // Intentionally notNull because Super POM may not contain a modelId
+ Objects.requireNonNull(modelId, "modelId cannot be null");
+
+ rawModels.put(modelId, rawModel);
+
+ return this;
+ }
+
+ @Override
+ public List<Profile> getActivePomProfiles(String modelId) {
+ List<Profile> profiles = activePomProfiles.get(modelId);
+ return profiles != null ? profiles : List.of();
+ }
+
+ public DefaultModelBuilderResult setActivePomProfiles(String modelId, List<Profile> activeProfiles) {
+ // Intentionally notNull because Super POM may not contain a modelId
+ Objects.requireNonNull(modelId, "modelId cannot be null");
+
+ if (activeProfiles != null) {
+ this.activePomProfiles.put(modelId, new ArrayList<>(activeProfiles));
+ } else {
+ this.activePomProfiles.remove(modelId);
+ }
+
+ return this;
+ }
+
+ @Override
+ public List<Profile> getActiveExternalProfiles() {
+ return activeExternalProfiles;
+ }
+
+ public DefaultModelBuilderResult setActiveExternalProfiles(List<Profile> activeProfiles) {
+ if (activeProfiles != null) {
+ this.activeExternalProfiles = new ArrayList<>(activeProfiles);
+ } else {
+ this.activeExternalProfiles.clear();
+ }
+
+ return this;
+ }
+
+ @Override
+ public List<ModelProblem> getProblems() {
+ return problems;
+ }
+
+ public DefaultModelBuilderResult setProblems(List<ModelProblem> problems) {
+ if (problems != null) {
+ this.problems = new ArrayList<>(problems);
+ } else {
+ this.problems.clear();
+ }
+
+ return this;
+ }
+
+ public String toString() {
+ if (!modelIds.isEmpty()) {
+ String modelId = modelIds.get(0);
+ StringBuilder sb = new StringBuilder();
+ sb.append(problems.size())
+ .append(
+ (problems.size() == 1)
+ ? " problem was "
+ : " problems were encountered while building the effective model");
+ if (modelId != null && !modelId.isEmpty()) {
+ sb.append(" for ");
+ sb.append(modelId);
+ }
+ for (ModelProblem problem : problems) {
+ sb.append(System.lineSeparator());
+ sb.append(" - [");
+ sb.append(problem.getSeverity());
+ sb.append("] ");
+ sb.append(problem.getMessage());
+ String loc = Stream.of(
+ problem.getModelId().equals(modelId) ? problem.getModelId() : "",
+ problem.getModelId().equals(modelId) ? problem.getSource() : "",
+ problem.getLineNumber() > 0 ? "line " + problem.getLineNumber() : "",
+ problem.getColumnNumber() > 0 ? "column " + problem.getColumnNumber() : "")
+ .filter(s -> !s.isEmpty())
+ .collect(Collectors.joining(", "));
+ if (!loc.isEmpty()) {
+ sb.append(" @ ").append(loc);
+ }
+ }
+ return sb.toString();
+ }
+ return null;
+ }
+}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuildingEvent.java
similarity index 56%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
copy to maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuildingEvent.java
index ca4c40d48a..db76a06866 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/TypeRegistry.java
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuildingEvent.java
@@ -16,28 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api.services;
+package org.apache.maven.internal.impl.model;
-import org.apache.maven.api.Type;
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Nonnull;
+import java.util.function.Consumer;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.services.model.ModelBuildingEvent;
/**
- * Access to {@link Type} registry.
- *
- * @since 4.0.0
+ * Holds data relevant for a model building event.
*/
-@Experimental
-public interface TypeRegistry extends ExtensibleEnumRegistry<Type> {
-
- /**
- * Obtain the {@link Type} from the specified {@code id}.
- * If no type is known for {@code id}, the registry will
- * create a custom {@code Type} for it.
- *
- * @param id the id of the type to retrieve
- * @return the type
- */
- @Nonnull
- Type require(@Nonnull String id);
-}
+record DefaultModelBuildingEvent(
+ Model model, Consumer<Model> update, ModelBuilderRequest request, ModelProblemCollector problems)
+ implements ModelBuildingEvent {}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java
new file mode 100644
index 0000000000..04fc7f8a93
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java
@@ -0,0 +1,485 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.net.URI;
+import java.nio.file.Path;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.BuilderProblem;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblem;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.services.model.*;
+import org.apache.maven.model.v4.MavenTransformer;
+import org.codehaus.plexus.interpolation.AbstractDelegatingValueSource;
+import org.codehaus.plexus.interpolation.AbstractValueSource;
+import org.codehaus.plexus.interpolation.InterpolationException;
+import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
+import org.codehaus.plexus.interpolation.MapBasedValueSource;
+import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor;
+import org.codehaus.plexus.interpolation.PrefixedValueSourceWrapper;
+import org.codehaus.plexus.interpolation.QueryEnabledValueSource;
+import org.codehaus.plexus.interpolation.RecursionInterceptor;
+import org.codehaus.plexus.interpolation.StringSearchInterpolator;
+import org.codehaus.plexus.interpolation.ValueSource;
+import org.codehaus.plexus.interpolation.reflection.ReflectionValueExtractor;
+import org.codehaus.plexus.interpolation.util.ValueSourceUtils;
+
+@Named
+@Singleton
+public class DefaultModelInterpolator implements ModelInterpolator {
+
+ private static final String PREFIX_PROJECT = "project.";
+ private static final String PREFIX_POM = "pom.";
+ private static final List<String> PROJECT_PREFIXES_3_1 = Arrays.asList(PREFIX_POM, PREFIX_PROJECT);
+ private static final List<String> PROJECT_PREFIXES_4_0 = Collections.singletonList(PREFIX_PROJECT);
+
+ private static final Collection<String> TRANSLATED_PATH_EXPRESSIONS;
+
+ static {
+ Collection<String> translatedPrefixes = new HashSet<>();
+
+ // MNG-1927, MNG-2124, MNG-3355:
+ // If the build section is present and the project directory is non-null, we should make
+ // sure interpolation of the directories below uses translated paths.
+ // Afterward, we'll double back and translate any paths that weren't covered during interpolation via the
+ // code below...
+ translatedPrefixes.add("build.directory");
+ translatedPrefixes.add("build.outputDirectory");
+ translatedPrefixes.add("build.testOutputDirectory");
+ translatedPrefixes.add("build.sourceDirectory");
+ translatedPrefixes.add("build.testSourceDirectory");
+ translatedPrefixes.add("build.scriptSourceDirectory");
+ translatedPrefixes.add("reporting.outputDirectory");
+
+ TRANSLATED_PATH_EXPRESSIONS = translatedPrefixes;
+ }
+
+ private final PathTranslator pathTranslator;
+ private final UrlNormalizer urlNormalizer;
+ private final RootLocator rootLocator;
+
+ @Inject
+ public DefaultModelInterpolator(
+ PathTranslator pathTranslator, UrlNormalizer urlNormalizer, RootLocator rootLocator) {
+ this.pathTranslator = pathTranslator;
+ this.urlNormalizer = urlNormalizer;
+ this.rootLocator = rootLocator;
+ }
+
+ interface InnerInterpolator {
+ String interpolate(String value);
+ }
+
+ @Override
+ public Model interpolateModel(
+ Model model, Path projectDir, ModelBuilderRequest request, ModelProblemCollector problems) {
+ List<? extends ValueSource> valueSources = createValueSources(model, projectDir, request, problems);
+ List<? extends InterpolationPostProcessor> postProcessors = createPostProcessors(model, projectDir, request);
+
+ InnerInterpolator innerInterpolator = createInterpolator(valueSources, postProcessors, request, problems);
+
+ return new MavenTransformer(innerInterpolator::interpolate).visit(model);
+ }
+
+ private InnerInterpolator createInterpolator(
+ List<? extends ValueSource> valueSources,
+ List<? extends InterpolationPostProcessor> postProcessors,
+ ModelBuilderRequest request,
+ ModelProblemCollector problems) {
+ Map<String, String> cache = new HashMap<>();
+ StringSearchInterpolator interpolator = new StringSearchInterpolator();
+ interpolator.setCacheAnswers(true);
+ for (ValueSource vs : valueSources) {
+ interpolator.addValueSource(vs);
+ }
+ for (InterpolationPostProcessor postProcessor : postProcessors) {
+ interpolator.addPostProcessor(postProcessor);
+ }
+ RecursionInterceptor recursionInterceptor = createRecursionInterceptor(request);
+ return value -> {
+ if (value != null && value.contains("${")) {
+ String c = cache.get(value);
+ if (c == null) {
+ try {
+ c = interpolator.interpolate(value, recursionInterceptor);
+ } catch (InterpolationException e) {
+ problems.add(BuilderProblem.Severity.ERROR, ModelProblem.Version.BASE, e.getMessage(), e);
+ }
+ cache.put(value, c);
+ }
+ return c;
+ }
+ return value;
+ };
+ }
+
+ protected List<String> getProjectPrefixes(ModelBuilderRequest request) {
+ return request.getValidationLevel() >= ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_4_0
+ ? PROJECT_PREFIXES_4_0
+ : PROJECT_PREFIXES_3_1;
+ }
+
+ protected List<ValueSource> createValueSources(
+ Model model, Path projectDir, ModelBuilderRequest request, ModelProblemCollector problems) {
+ Map<String, String> modelProperties = model.getProperties();
+
+ ValueSource projectPrefixValueSource;
+ ValueSource prefixlessObjectBasedValueSource;
+ if (request.getValidationLevel() >= ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_4_0) {
+ projectPrefixValueSource = new PrefixedObjectValueSource(PROJECT_PREFIXES_4_0, model, false);
+ prefixlessObjectBasedValueSource = new ObjectBasedValueSource(model);
+ } else {
+ projectPrefixValueSource = new PrefixedObjectValueSource(PROJECT_PREFIXES_3_1, model, false);
+ if (request.getValidationLevel() >= ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_2_0) {
+ projectPrefixValueSource =
+ new ProblemDetectingValueSource(projectPrefixValueSource, PREFIX_POM, PREFIX_PROJECT, problems);
+ }
+
+ prefixlessObjectBasedValueSource = new ObjectBasedValueSource(model);
+ if (request.getValidationLevel() >= ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_2_0) {
+ prefixlessObjectBasedValueSource =
+ new ProblemDetectingValueSource(prefixlessObjectBasedValueSource, "", PREFIX_PROJECT, problems);
+ }
+ }
+
+ // NOTE: Order counts here!
+ List<ValueSource> valueSources = new ArrayList<>(9);
+
+ if (projectDir != null) {
+ ValueSource basedirValueSource = new PrefixedValueSourceWrapper(
+ new AbstractValueSource(false) {
+ @Override
+ public Object getValue(String expression) {
+ if ("basedir".equals(expression)) {
+ return projectDir.toAbsolutePath().toString();
+ } else if (expression.startsWith("basedir.")) {
+ Path basedir = projectDir.toAbsolutePath();
+ return new ObjectBasedValueSource(basedir)
+ .getValue(expression.substring("basedir.".length()));
+ }
+ return null;
+ }
+ },
+ getProjectPrefixes(request),
+ true);
+ valueSources.add(basedirValueSource);
+
+ ValueSource baseUriValueSource = new PrefixedValueSourceWrapper(
+ new AbstractValueSource(false) {
+ @Override
+ public Object getValue(String expression) {
+ if ("baseUri".equals(expression)) {
+ return projectDir.toAbsolutePath().toUri().toASCIIString();
+ } else if (expression.startsWith("baseUri.")) {
+ URI baseUri = projectDir.toAbsolutePath().toUri();
+ return new ObjectBasedValueSource(baseUri)
+ .getValue(expression.substring("baseUri.".length()));
+ }
+ return null;
+ }
+ },
+ getProjectPrefixes(request),
+ false);
+ valueSources.add(baseUriValueSource);
+ valueSources.add(new BuildTimestampValueSource(request.getSession().getStartTime(), modelProperties));
+ }
+
+ valueSources.add(new PrefixedValueSourceWrapper(
+ new AbstractValueSource(false) {
+ @Override
+ public Object getValue(String expression) {
+ if ("rootDirectory".equals(expression)) {
+ Path root = rootLocator.findMandatoryRoot(projectDir);
+ return root.toFile().getPath();
+ } else if (expression.startsWith("rootDirectory.")) {
+ Path root = rootLocator.findMandatoryRoot(projectDir);
+ return new ObjectBasedValueSource(root)
+ .getValue(expression.substring("rootDirectory.".length()));
+ }
+ return null;
+ }
+ },
+ getProjectPrefixes(request)));
+
+ valueSources.add(projectPrefixValueSource);
+
+ valueSources.add(new MapBasedValueSource(request.getUserProperties()));
+
+ valueSources.add(new MapBasedValueSource(modelProperties));
+
+ valueSources.add(new MapBasedValueSource(request.getSystemProperties()));
+
+ valueSources.add(new AbstractValueSource(false) {
+ @Override
+ public Object getValue(String expression) {
+ return request.getSystemProperties().get("env." + expression);
+ }
+ });
+
+ valueSources.add(prefixlessObjectBasedValueSource);
+
+ return valueSources;
+ }
+
+ protected List<? extends InterpolationPostProcessor> createPostProcessors(
+ Model model, Path projectDir, ModelBuilderRequest request) {
+ List<InterpolationPostProcessor> processors = new ArrayList<>(2);
+ if (projectDir != null) {
+ processors.add(new PathTranslatingPostProcessor(
+ getProjectPrefixes(request), TRANSLATED_PATH_EXPRESSIONS, projectDir, pathTranslator));
+ }
+ processors.add(new UrlNormalizingPostProcessor(urlNormalizer));
+ return processors;
+ }
+
+ protected RecursionInterceptor createRecursionInterceptor(ModelBuilderRequest request) {
+ return new PrefixAwareRecursionInterceptor(getProjectPrefixes(request));
+ }
+
+ static class PathTranslatingPostProcessor implements InterpolationPostProcessor {
+
+ private final Collection<String> unprefixedPathKeys;
+ private final Path projectDir;
+ private final PathTranslator pathTranslator;
+ private final List<String> expressionPrefixes;
+
+ PathTranslatingPostProcessor(
+ List<String> expressionPrefixes,
+ Collection<String> unprefixedPathKeys,
+ Path projectDir,
+ PathTranslator pathTranslator) {
+ this.expressionPrefixes = expressionPrefixes;
+ this.unprefixedPathKeys = unprefixedPathKeys;
+ this.projectDir = projectDir;
+ this.pathTranslator = pathTranslator;
+ }
+
+ @Override
+ public Object execute(String expression, Object value) {
+ if (value != null) {
+ expression = ValueSourceUtils.trimPrefix(expression, expressionPrefixes, true);
+ if (unprefixedPathKeys.contains(expression)) {
+ return pathTranslator.alignToBaseDirectory(String.valueOf(value), projectDir);
+ }
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Ensures that expressions referring to URLs evaluate to normalized URLs.
+ *
+ */
+ static class UrlNormalizingPostProcessor implements InterpolationPostProcessor {
+
+ private static final Set<String> URL_EXPRESSIONS;
+
+ static {
+ Set<String> expressions = new HashSet<>();
+ expressions.add("project.url");
+ expressions.add("project.scm.url");
+ expressions.add("project.scm.connection");
+ expressions.add("project.scm.developerConnection");
+ expressions.add("project.distributionManagement.site.url");
+ URL_EXPRESSIONS = expressions;
+ }
+
+ private final UrlNormalizer normalizer;
+
+ UrlNormalizingPostProcessor(UrlNormalizer normalizer) {
+ this.normalizer = normalizer;
+ }
+
+ @Override
+ public Object execute(String expression, Object value) {
+ if (value != null && URL_EXPRESSIONS.contains(expression)) {
+ return normalizer.normalize(value.toString());
+ }
+
+ return null;
+ }
+ }
+
+ /**
+ * Wraps an arbitrary object with an {@link ObjectBasedValueSource} instance, then
+ * wraps that source with a {@link PrefixedValueSourceWrapper} instance, to which
+ * this class delegates all of its calls.
+ */
+ public static class PrefixedObjectValueSource extends AbstractDelegatingValueSource
+ implements QueryEnabledValueSource {
+
+ /**
+ * Wrap the specified root object, allowing the specified expression prefix.
+ * @param prefix the prefix.
+ * @param root the root of the graph.
+ */
+ public PrefixedObjectValueSource(String prefix, Object root) {
+ super(new PrefixedValueSourceWrapper(new ObjectBasedValueSource(root), prefix));
+ }
+
+ /**
+ * Wrap the specified root object, allowing the specified list of expression
+ * prefixes and setting whether the {@link PrefixedValueSourceWrapper} allows
+ * unprefixed expressions.
+ * @param possiblePrefixes The possible prefixes.
+ * @param root The root of the graph.
+ * @param allowUnprefixedExpressions if we allow undefined expressions or not.
+ */
+ public PrefixedObjectValueSource(
+ List<String> possiblePrefixes, Object root, boolean allowUnprefixedExpressions) {
+ super(new PrefixedValueSourceWrapper(
+ new ObjectBasedValueSource(root), possiblePrefixes, allowUnprefixedExpressions));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getLastExpression() {
+ return ((QueryEnabledValueSource) getDelegate()).getLastExpression();
+ }
+ }
+
+ /**
+ * Wraps an object, providing reflective access to the object graph of which the
+ * supplied object is the root. Expressions like 'child.name' will translate into
+ * 'rootObject.getChild().getName()' for non-boolean properties, and
+ * 'rootObject.getChild().isName()' for boolean properties.
+ */
+ public static class ObjectBasedValueSource extends AbstractValueSource {
+
+ private final Object root;
+
+ /**
+ * Construct a new value source, using the supplied object as the root from
+ * which to start, and using expressions split at the dot ('.') to navigate
+ * the object graph beneath this root.
+ * @param root the root of the graph.
+ */
+ public ObjectBasedValueSource(Object root) {
+ super(true);
+ this.root = root;
+ }
+
+ /**
+ * <p>Split the expression into parts, tokenized on the dot ('.') character. Then,
+ * starting at the root object contained in this value source, apply each part
+ * to the object graph below this root, using either 'getXXX()' or 'isXXX()'
+ * accessor types to resolve the value for each successive expression part.
+ * Finally, return the result of the last expression part's resolution.</p>
+ *
+ * <p><b>NOTE:</b> The object-graph nagivation actually takes place via the
+ * {@link ReflectionValueExtractor} class.</p>
+ */
+ public Object getValue(String expression) {
+ if (expression == null || expression.trim().isEmpty()) {
+ return null;
+ }
+
+ try {
+ return ReflectionValueExtractor.evaluate(expression, root, false);
+ } catch (Exception e) {
+ addFeedback("Failed to extract \'" + expression + "\' from: " + root, e);
+ }
+
+ return null;
+ }
+ }
+
+ /**
+ * Wraps another value source and intercepts interpolated expressions, checking for problems.
+ *
+ */
+ static class ProblemDetectingValueSource implements ValueSource {
+
+ private final ValueSource valueSource;
+
+ private final String bannedPrefix;
+
+ private final String newPrefix;
+
+ private final ModelProblemCollector problems;
+
+ ProblemDetectingValueSource(
+ ValueSource valueSource, String bannedPrefix, String newPrefix, ModelProblemCollector problems) {
+ this.valueSource = valueSource;
+ this.bannedPrefix = bannedPrefix;
+ this.newPrefix = newPrefix;
+ this.problems = problems;
+ }
+
+ @Override
+ public Object getValue(String expression) {
+ Object value = valueSource.getValue(expression);
+
+ if (value != null && expression.startsWith(bannedPrefix)) {
+ String msg = "The expression ${" + expression + "} is deprecated.";
+ if (newPrefix != null && !newPrefix.isEmpty()) {
+ msg += " Please use ${" + newPrefix + expression.substring(bannedPrefix.length()) + "} instead.";
+ }
+ problems.add(BuilderProblem.Severity.WARNING, ModelProblem.Version.V20, msg);
+ }
+
+ return value;
+ }
+
+ @Override
+ public List getFeedback() {
+ return valueSource.getFeedback();
+ }
+
+ @Override
+ public void clearFeedback() {
+ valueSource.clearFeedback();
+ }
+ }
+
+ static class BuildTimestampValueSource extends AbstractValueSource {
+ private final Instant startTime;
+ private final Map<String, String> properties;
+
+ BuildTimestampValueSource(Instant startTime, Map<String, String> properties) {
+ super(false);
+ this.startTime = startTime;
+ this.properties = properties;
+ }
+
+ @Override
+ public Object getValue(String expression) {
+ if ("build.timestamp".equals(expression) || "maven.build.timestamp".equals(expression)) {
+ return new MavenBuildTimestamp(startTime, properties).formattedTimestamp();
+ }
+ return null;
+ }
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelNormalizer.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelNormalizer.java
new file mode 100644
index 0000000000..714e56e392
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelNormalizer.java
@@ -0,0 +1,147 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.Build;
+import org.apache.maven.api.model.Dependency;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Plugin;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.services.model.*;
+
+/**
+ * Handles normalization of a model.
+ *
+ */
+@Named
+@Singleton
+public class DefaultModelNormalizer implements ModelNormalizer {
+
+ private DuplicateMerger merger = new DuplicateMerger();
+
+ @Override
+ public Model mergeDuplicates(Model model, ModelBuilderRequest request, ModelProblemCollector problems) {
+ Model.Builder builder = Model.newBuilder(model);
+
+ Build build = model.getBuild();
+ if (build != null) {
+ List<Plugin> plugins = build.getPlugins();
+ Map<Object, Plugin> normalized = new LinkedHashMap<>(plugins.size() * 2);
+
+ for (Plugin plugin : plugins) {
+ Object key = plugin.getKey();
+ Plugin first = normalized.get(key);
+ if (first != null) {
+ plugin = merger.mergePlugin(plugin, first);
+ }
+ normalized.put(key, plugin);
+ }
+
+ if (plugins.size() != normalized.size()) {
+ builder.build(
+ Build.newBuilder(build).plugins(normalized.values()).build());
+ }
+ }
+
+ /*
+ * NOTE: This is primarily to keep backward-compat with Maven 2.x which did not validate that dependencies are
+ * unique within a single POM. Upon multiple declarations, 2.x just kept the last one but retained the order of
+ * the first occurrence. So when we're in lenient/compat mode, we have to deal with such broken POMs and mimic
+ * the way 2.x works. When we're in strict mode, the removal of duplicates just saves other merging steps from
+ * aftereffects and bogus error messages.
+ */
+ List<Dependency> dependencies = model.getDependencies();
+ Map<String, Dependency> normalized = new LinkedHashMap<>(dependencies.size() * 2);
+
+ for (Dependency dependency : dependencies) {
+ normalized.put(dependency.getManagementKey(), dependency);
+ }
+
+ if (dependencies.size() != normalized.size()) {
+ builder.dependencies(normalized.values());
+ }
+
+ return builder.build();
+ }
+
+ /**
+ * DuplicateMerger
+ */
+ protected static class DuplicateMerger extends MavenModelMerger {
+
+ public Plugin mergePlugin(Plugin target, Plugin source) {
+ return super.mergePlugin(target, source, false, Collections.emptyMap());
+ }
+ }
+
+ @Override
+ public Model injectDefaultValues(Model model, ModelBuilderRequest request, ModelProblemCollector problems) {
+ Model.Builder builder = Model.newBuilder(model);
+
+ builder.dependencies(injectList(model.getDependencies(), this::injectDependency));
+ Build build = model.getBuild();
+ if (build != null) {
+ Build newBuild = Build.newBuilder(build)
+ .plugins(injectList(build.getPlugins(), this::injectPlugin))
+ .build();
+ builder.build(newBuild != build ? newBuild : null);
+ }
+
+ return builder.build();
+ }
+
+ private Plugin injectPlugin(Plugin p) {
+ return Plugin.newBuilder(p)
+ .dependencies(injectList(p.getDependencies(), this::injectDependency))
+ .build();
+ }
+
+ private Dependency injectDependency(Dependency d) {
+ // we cannot set this directly in the MDO due to the interactions with dependency management
+ return (d.getScope() == null || d.getScope().isEmpty()) ? d.withScope("compile") : d;
+ }
+
+ /**
+ * Returns a list suited for the builders, i.e. null if not modified
+ */
+ private <T> List<T> injectList(List<T> list, Function<T, T> modifer) {
+ List<T> newList = null;
+ for (int i = 0; i < list.size(); i++) {
+ T oldT = list.get(i);
+ T newT = modifer.apply(oldT);
+ if (newT != oldT) {
+ if (newList == null) {
+ newList = new ArrayList<>(list);
+ }
+ newList.set(i, newT);
+ }
+ }
+ return newList;
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelPathTranslator.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelPathTranslator.java
new file mode 100644
index 0000000000..1d733c5de9
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelPathTranslator.java
@@ -0,0 +1,121 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.Build;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Reporting;
+import org.apache.maven.api.model.Resource;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.model.*;
+
+/**
+ * Resolves relative paths within a model against a specific base directory.
+ *
+ */
+@Named
+@Singleton
+public class DefaultModelPathTranslator implements ModelPathTranslator {
+
+ private final PathTranslator pathTranslator;
+
+ @Inject
+ public DefaultModelPathTranslator(PathTranslator pathTranslator) {
+ this.pathTranslator = pathTranslator;
+ }
+
+ @Override
+ public Model alignToBaseDirectory(Model model, Path basedir, ModelBuilderRequest request) {
+ if (model == null || basedir == null) {
+ return model;
+ }
+
+ Build build = model.getBuild();
+ Build newBuild = null;
+ if (build != null) {
+ newBuild = Build.newBuilder(build)
+ .directory(alignToBaseDirectory(build.getDirectory(), basedir))
+ .sourceDirectory(alignToBaseDirectory(build.getSourceDirectory(), basedir))
+ .testSourceDirectory(alignToBaseDirectory(build.getTestSourceDirectory(), basedir))
+ .scriptSourceDirectory(alignToBaseDirectory(build.getScriptSourceDirectory(), basedir))
+ .resources(map(build.getResources(), r -> alignToBaseDirectory(r, basedir)))
+ .testResources(map(build.getTestResources(), r -> alignToBaseDirectory(r, basedir)))
+ .filters(map(build.getFilters(), s -> alignToBaseDirectory(s, basedir)))
+ .outputDirectory(alignToBaseDirectory(build.getOutputDirectory(), basedir))
+ .testOutputDirectory(alignToBaseDirectory(build.getTestOutputDirectory(), basedir))
+ .build();
+ }
+
+ Reporting reporting = model.getReporting();
+ Reporting newReporting = null;
+ if (reporting != null) {
+ newReporting = Reporting.newBuilder(reporting)
+ .outputDirectory(alignToBaseDirectory(reporting.getOutputDirectory(), basedir))
+ .build();
+ }
+ if (newBuild != build || newReporting != reporting) {
+ model = Model.newBuilder(model)
+ .build(newBuild)
+ .reporting(newReporting)
+ .build();
+ }
+ return model;
+ }
+
+ private <T> List<T> map(List<T> resources, Function<T, T> mapper) {
+ List<T> newResources = null;
+ if (resources != null) {
+ for (int i = 0; i < resources.size(); i++) {
+ T resource = resources.get(i);
+ T newResource = mapper.apply(resource);
+ if (newResource != null) {
+ if (newResources == null) {
+ newResources = new ArrayList<>(resources);
+ }
+ newResources.set(i, newResource);
+ }
+ }
+ }
+ return newResources;
+ }
+
+ private Resource alignToBaseDirectory(Resource resource, Path basedir) {
+ if (resource != null) {
+ String newDir = alignToBaseDirectory(resource.getDirectory(), basedir);
+ if (newDir != null) {
+ return resource.withDirectory(newDir);
+ }
+ }
+ return resource;
+ }
+
+ private String alignToBaseDirectory(String path, Path basedir) {
+ String newPath = pathTranslator.alignToBaseDirectory(path, basedir);
+ return Objects.equals(path, newPath) ? null : newPath;
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProblem.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProblem.java
new file mode 100644
index 0000000000..f30bffddf2
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProblem.java
@@ -0,0 +1,182 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelProblem;
+
+/**
+ * Describes a problem that was encountered during model building. A problem can either be an exception that was thrown
+ * or a simple string message. In addition, a problem carries a hint about its source, e.g. the POM file that exhibits
+ * the problem.
+ *
+ */
+public class DefaultModelProblem implements ModelProblem {
+
+ private final String source;
+
+ private final int lineNumber;
+
+ private final int columnNumber;
+
+ private final String modelId;
+
+ private final String message;
+
+ private final Exception exception;
+
+ private final Severity severity;
+
+ private final Version version;
+
+ /**
+ * Creates a new problem with the specified message and exception.
+ *
+ * @param message The message describing the problem, may be {@code null}.
+ * @param severity The severity level of the problem, may be {@code null} to default to
+ * {@link Severity#ERROR}.
+ * @param source The source of the problem, may be {@code null}.
+ * @param lineNumber The one-based index of the line containing the error or {@code -1} if unknown.
+ * @param columnNumber The one-based index of the column containing the error or {@code -1} if unknown.
+ * @param exception The exception that caused this problem, may be {@code null}.
+ */
+ // mkleint: does this need to be public?
+ public DefaultModelProblem(
+ String message,
+ Severity severity,
+ Version version,
+ Model source,
+ int lineNumber,
+ int columnNumber,
+ Exception exception) {
+ this(
+ message,
+ severity,
+ version,
+ ModelProblemUtils.toPath(source),
+ lineNumber,
+ columnNumber,
+ ModelProblemUtils.toId(source),
+ exception);
+ }
+
+ /**
+ * Creates a new problem with the specified message and exception.
+ *
+ * @param message The message describing the problem, may be {@code null}.
+ * @param severity The severity level of the problem, may be {@code null} to default to
+ * {@link Severity#ERROR}.
+ * @param version The version since the problem is relevant
+ * @param source A hint about the source of the problem like a file path, may be {@code null}.
+ * @param lineNumber The one-based index of the line containing the problem or {@code -1} if unknown.
+ * @param columnNumber The one-based index of the column containing the problem or {@code -1} if unknown.
+ * @param modelId The identifier of the model that exhibits the problem, may be {@code null}.
+ * @param exception The exception that caused this problem, may be {@code null}.
+ */
+ // mkleint: does this need to be public?
+ @SuppressWarnings("checkstyle:parameternumber")
+ public DefaultModelProblem(
+ String message,
+ Severity severity,
+ Version version,
+ String source,
+ int lineNumber,
+ int columnNumber,
+ String modelId,
+ Exception exception) {
+ this.message = message;
+ this.severity = (severity != null) ? severity : Severity.ERROR;
+ this.source = (source != null) ? source : "";
+ this.lineNumber = lineNumber;
+ this.columnNumber = columnNumber;
+ this.modelId = (modelId != null) ? modelId : "";
+ this.exception = exception;
+ this.version = version;
+ }
+
+ @Override
+ public String getSource() {
+ return source;
+ }
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public int getColumnNumber() {
+ return columnNumber;
+ }
+
+ public String getModelId() {
+ return modelId;
+ }
+
+ @Override
+ public Exception getException() {
+ return exception;
+ }
+
+ @Override
+ public String getLocation() {
+ return "";
+ }
+
+ @Override
+ public String getMessage() {
+ String msg = null;
+
+ if (message != null && !message.isEmpty()) {
+ msg = message;
+ } else if (exception != null) {
+ msg = exception.getMessage();
+ }
+
+ if (msg == null) {
+ msg = "";
+ }
+
+ return msg;
+ }
+
+ @Override
+ public Severity getSeverity() {
+ return severity;
+ }
+
+ public Version getVersion() {
+ return version;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buffer = new StringBuilder(128);
+
+ buffer.append('[').append(getSeverity()).append("] ");
+ buffer.append(getMessage());
+ String location = ModelProblemUtils.formatLocation(this, null);
+ if (!location.isEmpty()) {
+ buffer.append(" @ ");
+ buffer.append(location);
+ }
+
+ return buffer.toString();
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProblemCollector.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProblemCollector.java
new file mode 100644
index 0000000000..8df0190522
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProblemCollector.java
@@ -0,0 +1,198 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.util.Collection;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.api.model.InputLocation;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.BuilderProblem;
+import org.apache.maven.api.services.ModelBuilderException;
+import org.apache.maven.api.services.ModelBuilderResult;
+import org.apache.maven.api.services.ModelProblem;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.spi.ModelParserException;
+
+/**
+ * Collects problems that are encountered during model building. The primary purpose of this component is to account for
+ * the fact that the problem reporter has/should not have information about the calling context and hence cannot provide
+ * an expressive source hint for the model problem. Instead, the source hint is configured by the model builder before
+ * it delegates to other components that potentially encounter problems. Then, the problem reporter can focus on
+ * providing a simple error message, leaving the donkey work of creating a nice model problem to this component.
+ *
+ */
+class DefaultModelProblemCollector implements ModelProblemCollector {
+
+ private final ModelBuilderResult result;
+
+ private List<ModelProblem> problems;
+
+ private String source;
+
+ private Model sourceModel;
+
+ private Model rootModel;
+
+ private Set<ModelProblem.Severity> severities = EnumSet.noneOf(ModelProblem.Severity.class);
+
+ DefaultModelProblemCollector(ModelBuilderResult result) {
+ this.result = result;
+ this.problems = result.getProblems();
+
+ for (ModelProblem problem : this.problems) {
+ severities.add(problem.getSeverity());
+ }
+ }
+
+ public boolean hasFatalErrors() {
+ return severities.contains(ModelProblem.Severity.FATAL);
+ }
+
+ public boolean hasErrors() {
+ return severities.contains(ModelProblem.Severity.ERROR) || severities.contains(ModelProblem.Severity.FATAL);
+ }
+
+ @Override
+ public List<ModelProblem> getProblems() {
+ return problems;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ this.sourceModel = null;
+ }
+
+ public void setSource(Model source) {
+ this.sourceModel = source;
+ this.source = null;
+
+ if (rootModel == null) {
+ rootModel = source;
+ }
+ }
+
+ private String getSource() {
+ if (source == null && sourceModel != null) {
+ source = ModelProblemUtils.toPath(sourceModel);
+ }
+ return source;
+ }
+
+ private String getModelId() {
+ return ModelProblemUtils.toId(sourceModel);
+ }
+
+ public void setRootModel(Model rootModel) {
+ this.rootModel = rootModel;
+ }
+
+ public Model getRootModel() {
+ return rootModel;
+ }
+
+ public String getRootModelId() {
+ return ModelProblemUtils.toId(rootModel);
+ }
+
+ @Override
+ public void add(ModelProblem problem) {
+ problems.add(problem);
+
+ severities.add(problem.getSeverity());
+ }
+
+ public void addAll(Collection<ModelProblem> problems) {
+ this.problems.addAll(problems);
+
+ for (ModelProblem problem : problems) {
+ severities.add(problem.getSeverity());
+ }
+ }
+
+ @Override
+ public void add(BuilderProblem.Severity severity, ModelProblem.Version version, String message) {
+ add(severity, version, message, null, null);
+ }
+
+ @Override
+ public void add(
+ BuilderProblem.Severity severity, ModelProblem.Version version, String message, InputLocation location) {
+ add(severity, version, message, location, null);
+ }
+
+ @Override
+ public void add(
+ BuilderProblem.Severity severity, ModelProblem.Version version, String message, Exception exception) {
+ add(severity, version, message, null, exception);
+ }
+
+ public void add(
+ BuilderProblem.Severity severity,
+ ModelProblem.Version version,
+ String message,
+ InputLocation location,
+ Exception exception) {
+ int line = -1;
+ int column = -1;
+ String source = null;
+ String modelId = null;
+
+ if (location != null) {
+ line = location.getLineNumber();
+ column = location.getColumnNumber();
+ if (location.getSource() != null) {
+ modelId = location.getSource().getModelId();
+ source = location.getSource().getLocation();
+ }
+ }
+
+ if (modelId == null) {
+ modelId = getModelId();
+ source = getSource();
+ }
+
+ if (line <= 0 && column <= 0 && exception instanceof ModelParserException e) {
+ line = e.getLineNumber();
+ column = e.getColumnNumber();
+ }
+
+ ModelProblem problem =
+ new DefaultModelProblem(message, severity, version, source, line, column, modelId, exception);
+
+ add(problem);
+ }
+
+ public ModelBuilderException newModelBuilderException() {
+ ModelBuilderResult result = this.result;
+ if (result.getModelIds().isEmpty()) {
+ DefaultModelBuilderResult tmp = new DefaultModelBuilderResult();
+ tmp.setEffectiveModel(result.getEffectiveModel());
+ tmp.setProblems(getProblems());
+ tmp.setActiveExternalProfiles(result.getActiveExternalProfiles());
+ String id = getRootModelId();
+ tmp.addModelId(id);
+ tmp.setRawModel(id, getRootModel());
+ result = tmp;
+ }
+ return new ModelBuilderException(result);
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProcessor.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProcessor.java
new file mode 100644
index 0000000000..626c3a903e
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelProcessor.java
@@ -0,0 +1,142 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.model.*;
+import org.apache.maven.api.services.xml.ModelXmlFactory;
+import org.apache.maven.api.services.xml.XmlReaderRequest;
+import org.apache.maven.api.spi.ModelParser;
+import org.apache.maven.api.spi.ModelParserException;
+
+/**
+ *
+ * Note: uses @Typed to limit the types it is available for injection to just ModelProcessor.
+ *
+ * This is because the ModelProcessor interface extends ModelLocator and ModelReader. If we
+ * made this component available under all its interfaces then it could end up being injected
+ * into itself leading to a stack overflow.
+ *
+ * A side effect of using @Typed is that it translates to explicit bindings in the container.
+ * So instead of binding the component under a 'wildcard' key it is now bound with an explicit
+ * key. Since this is a default component this will be a plain binding of ModelProcessor to
+ * this implementation type, ie. no hint/name.
+ *
+ * This leads to a second side effect in that any @Inject request for just ModelProcessor in
+ * the same injector is immediately matched to this explicit binding, which means extensions
+ * cannot override this binding. This is because the lookup is always short-circuited in this
+ * specific situation (plain @Inject request, and plain explicit binding for the same type.)
+ *
+ * The simplest solution is to use a custom @Named here so it isn't bound under the plain key.
+ * This is only necessary for default components using @Typed that want to support overriding.
+ *
+ * As a non-default component this now gets a negative priority relative to other implementations
+ * of the same interface. Since we want to allow overriding this doesn't matter in this case.
+ * (if it did we could add @Priority of 0 to match the priority given to default components.)
+ */
+@Named
+@Singleton
+public class DefaultModelProcessor implements ModelProcessor {
+
+ private final ModelXmlFactory modelXmlFactory;
+ private final List<ModelParser> modelParsers;
+
+ @Inject
+ public DefaultModelProcessor(ModelXmlFactory modelXmlFactory, List<ModelParser> modelParsers) {
+ this.modelXmlFactory = modelXmlFactory;
+ this.modelParsers = modelParsers;
+ }
+
+ @Override
+ public Path locateExistingPom(Path projectDirectory) {
+ // Note that the ModelProcessor#locatePom never returns null
+ // while the ModelParser#locatePom needs to return an existing path!
+ Path pom = modelParsers.stream()
+ .map(m -> m.locate(projectDirectory)
+ .map(org.apache.maven.api.services.Source::getPath)
+ .orElse(null))
+ .filter(Objects::nonNull)
+ .findFirst()
+ .orElseGet(() -> doLocateExistingPom(projectDirectory));
+ if (pom != null && !pom.equals(projectDirectory) && !pom.getParent().equals(projectDirectory)) {
+ throw new IllegalArgumentException("The POM found does not belong to the given directory: " + pom);
+ }
+ return pom;
+ }
+
+ @Override
+ public Model read(XmlReaderRequest request) throws IOException {
+ Objects.requireNonNull(request, "source cannot be null");
+ Path pomFile = request.getPath();
+ if (pomFile != null) {
+ Path projectDirectory = pomFile.getParent();
+ List<ModelParserException> exceptions = new ArrayList<>();
+ for (ModelParser parser : modelParsers) {
+ try {
+ Optional<Model> model =
+ parser.locateAndParse(projectDirectory, Map.of(ModelParser.STRICT, request.isStrict()));
+ if (model.isPresent()) {
+ return model.get().withPomFile(pomFile);
+ }
+ } catch (ModelParserException e) {
+ exceptions.add(e);
+ }
+ }
+ try {
+ return doRead(request);
+ } catch (IOException e) {
+ exceptions.forEach(e::addSuppressed);
+ throw e;
+ }
+ } else {
+ return doRead(request);
+ }
+ }
+
+ private Path doLocateExistingPom(Path project) {
+ if (project == null) {
+ project = Paths.get(System.getProperty("user.dir"));
+ }
+ if (Files.isDirectory(project)) {
+ Path pom = project.resolve("pom.xml");
+ return Files.isRegularFile(pom) ? pom : null;
+ } else if (Files.isRegularFile(project)) {
+ return project;
+ } else {
+ return null;
+ }
+ }
+
+ private Model doRead(XmlReaderRequest request) throws IOException {
+ return modelXmlFactory.read(request);
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContext.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContext.java
new file mode 100644
index 0000000000..69415b3483
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContext.java
@@ -0,0 +1,141 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelTransformerContext;
+import org.apache.maven.api.services.model.*;
+
+/**
+ *
+ * @since 4.0.0
+ */
+class DefaultModelTransformerContext implements ModelTransformerContext {
+ final ModelProcessor modelLocator;
+
+ final Map<String, String> userProperties = new ConcurrentHashMap<>();
+
+ final Map<Path, Holder> modelByPath = new ConcurrentHashMap<>();
+
+ final Map<GAKey, Holder> modelByGA = new ConcurrentHashMap<>();
+
+ public static class Holder {
+ private volatile boolean set;
+ private volatile Model model;
+
+ Holder() {}
+
+ Holder(Model model) {
+ this.model = Objects.requireNonNull(model);
+ this.set = true;
+ }
+
+ public static Model deref(Holder holder) {
+ return holder != null ? holder.get() : null;
+ }
+
+ public Model get() {
+ if (!set) {
+ synchronized (this) {
+ if (!set) {
+ try {
+ this.wait();
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ return model;
+ }
+
+ public Model computeIfAbsent(Supplier<Model> supplier) {
+ if (!set) {
+ synchronized (this) {
+ if (!set) {
+ this.set = true;
+ this.model = supplier.get();
+ this.notifyAll();
+ }
+ }
+ }
+ return model;
+ }
+ }
+
+ DefaultModelTransformerContext(ModelProcessor modelLocator) {
+ this.modelLocator = modelLocator;
+ }
+
+ @Override
+ public String getUserProperty(String key) {
+ return userProperties.get(key);
+ }
+
+ @Override
+ public Model getRawModel(Path from, Path p) {
+ return Holder.deref(modelByPath.get(p));
+ }
+
+ @Override
+ public Model getRawModel(Path from, String groupId, String artifactId) {
+ return Holder.deref(modelByGA.get(new GAKey(groupId, artifactId)));
+ }
+
+ @Override
+ public Path locate(Path path) {
+ return modelLocator.locateExistingPom(path);
+ }
+
+ static class GAKey {
+ private final String groupId;
+ private final String artifactId;
+ private final int hashCode;
+
+ GAKey(String groupId, String artifactId) {
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.hashCode = Objects.hash(groupId, artifactId);
+ }
+
+ @Override
+ public int hashCode() {
+ return hashCode;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof GAKey)) {
+ return false;
+ }
+
+ GAKey other = (GAKey) obj;
+ return Objects.equals(artifactId, other.artifactId) && Objects.equals(groupId, other.groupId);
+ }
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContextBuilder.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContextBuilder.java
new file mode 100644
index 0000000000..42ba5eed3c
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelTransformerContextBuilder.java
@@ -0,0 +1,231 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.ModelBuilderException;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblem;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.services.ModelSource;
+import org.apache.maven.api.services.ModelTransformerContext;
+import org.apache.maven.api.services.ModelTransformerContextBuilder;
+import org.apache.maven.internal.impl.model.DefaultModelTransformerContext.GAKey;
+import org.apache.maven.internal.impl.model.DefaultModelTransformerContext.Holder;
+
+/**
+ * Builds up the transformer context.
+ * After the buildplan is ready, the build()-method returns the immutable context useful during distribution.
+ * This is an inner class, as it must be able to call readRawModel()
+ *
+ * @since 4.0.0
+ */
+class DefaultModelTransformerContextBuilder implements ModelTransformerContextBuilder {
+ private final Graph dag = new Graph();
+ private final DefaultModelBuilder defaultModelBuilder;
+ private final DefaultModelTransformerContext context;
+
+ private final Map<String, Set<ModelSource>> mappedSources = new ConcurrentHashMap<>(64);
+
+ private volatile boolean fullReactorLoaded;
+
+ DefaultModelTransformerContextBuilder(DefaultModelBuilder defaultModelBuilder) {
+ this.defaultModelBuilder = defaultModelBuilder;
+ this.context = new DefaultModelTransformerContext(defaultModelBuilder.getModelProcessor());
+ }
+
+ /**
+ * If an interface could be extracted, DefaultModelProblemCollector should be ModelProblemCollectorExt
+ */
+ @Override
+ public ModelTransformerContext initialize(ModelBuilderRequest request, ModelProblemCollector collector) {
+ // We must assume the TransformerContext was created using this.newTransformerContextBuilder()
+ DefaultModelProblemCollector problems = (DefaultModelProblemCollector) collector;
+ return new ModelTransformerContext() {
+
+ @Override
+ public Path locate(Path path) {
+ return context.locate(path);
+ }
+
+ @Override
+ public String getUserProperty(String key) {
+ return context.userProperties.computeIfAbsent(
+ key, k -> request.getUserProperties().get(key));
+ }
+
+ @Override
+ public Model getRawModel(Path from, String gId, String aId) {
+ Model model = findRawModel(from, gId, aId);
+ if (model != null) {
+ context.modelByGA.put(new GAKey(gId, aId), new Holder(model));
+ context.modelByPath.put(model.getPomFile(), new Holder(model));
+ }
+ return model;
+ }
+
+ @Override
+ public Model getRawModel(Path from, Path path) {
+ Model model = findRawModel(from, path);
+ if (model != null) {
+ String groupId = DefaultModelBuilder.getGroupId(model);
+ context.modelByGA.put(
+ new DefaultModelTransformerContext.GAKey(groupId, model.getArtifactId()),
+ new Holder(model));
+ context.modelByPath.put(path, new Holder(model));
+ }
+ return model;
+ }
+
+ private Model findRawModel(Path from, String groupId, String artifactId) {
+ ModelSource source = getSource(groupId, artifactId);
+ if (source == null) {
+ // we need to check the whole reactor in case it's a dependency
+ loadFullReactor();
+ source = getSource(groupId, artifactId);
+ }
+ if (source != null) {
+ if (!addEdge(from, source.getPath(), problems)) {
+ return null;
+ }
+ try {
+ ModelBuilderRequest gaBuildingRequest = ModelBuilderRequest.build(request, source);
+ return defaultModelBuilder.readRawModel(gaBuildingRequest, problems);
+ } catch (ModelBuilderException e) {
+ // gathered with problem collector
+ }
+ }
+ return null;
+ }
+
+ private void loadFullReactor() {
+ if (!fullReactorLoaded) {
+ synchronized (DefaultModelTransformerContextBuilder.this) {
+ if (!fullReactorLoaded) {
+ doLoadFullReactor();
+ fullReactorLoaded = true;
+ }
+ }
+ }
+ }
+
+ private void doLoadFullReactor() {
+ Path rootDirectory;
+ try {
+ rootDirectory = request.getSession().getRootDirectory();
+ } catch (IllegalStateException e) {
+ // if no root directory, bail out
+ return;
+ }
+ List<Path> toLoad = new ArrayList<>();
+ Path root = defaultModelBuilder.getModelProcessor().locateExistingPom(rootDirectory);
+ toLoad.add(root);
+ while (!toLoad.isEmpty()) {
+ Path pom = toLoad.remove(0);
+ try {
+ ModelBuilderRequest gaBuildingRequest =
+ ModelBuilderRequest.build(request, ModelSource.fromPath(pom));
+ Model rawModel = defaultModelBuilder.readFileModel(gaBuildingRequest, problems);
+ for (String module : rawModel.getModules()) {
+ Path moduleFile = defaultModelBuilder
+ .getModelProcessor()
+ .locateExistingPom(pom.getParent().resolve(module));
+ if (moduleFile != null) {
+ toLoad.add(moduleFile);
+ }
+ }
+ } catch (ModelBuilderException e) {
+ // gathered with problem collector
+ }
+ }
+ }
+
+ private Model findRawModel(Path from, Path p) {
+ if (!Files.isRegularFile(p)) {
+ throw new IllegalArgumentException("Not a regular file: " + p);
+ }
+
+ if (!addEdge(from, p, problems)) {
+ return null;
+ }
+
+ ModelBuilderRequest req = ModelBuilderRequest.build(request, ModelSource.fromPath(p));
+
+ try {
+ return defaultModelBuilder.readRawModel(req, problems);
+ } catch (ModelBuilderException e) {
+ // gathered with problem collector
+ }
+ return null;
+ }
+ };
+ }
+
+ private boolean addEdge(Path from, Path p, DefaultModelProblemCollector problems) {
+ try {
+ dag.addEdge(from.toString(), p.toString());
+ return true;
+ } catch (Graph.CycleDetectedException e) {
+ problems.add(new DefaultModelProblem(
+ "Cycle detected between models at " + from + " and " + p,
+ ModelProblem.Severity.FATAL,
+ null,
+ null,
+ 0,
+ 0,
+ null,
+ e));
+ return false;
+ }
+ }
+
+ @Override
+ public ModelTransformerContext build() {
+ return context;
+ }
+
+ public ModelSource getSource(String groupId, String artifactId) {
+ Set<ModelSource> sources = mappedSources.get(groupId + ":" + artifactId);
+ if (sources == null) {
+ return null;
+ }
+ return sources.stream()
+ .reduce((a, b) -> {
+ throw new IllegalStateException(String.format(
+ "No unique Source for %s:%s: %s and %s",
+ groupId, artifactId, a.getLocation(), b.getLocation()));
+ })
+ .orElse(null);
+ }
+
+ public void putSource(String groupId, String artifactId, ModelSource source) {
+ mappedSources
+ .computeIfAbsent(groupId + ":" + artifactId, k -> new HashSet<>())
+ .add(source);
+ }
+}
diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java
new file mode 100644
index 0000000000..120a34e419
--- /dev/null
+++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java
@@ -0,0 +1,1742 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl.model;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.model.Activation;
+import org.apache.maven.api.model.ActivationFile;
+import org.apache.maven.api.model.Build;
+import org.apache.maven.api.model.BuildBase;
+import org.apache.maven.api.model.Dependency;
+import org.apache.maven.api.model.DependencyManagement;
+import org.apache.maven.api.model.DistributionManagement;
+import org.apache.maven.api.model.Exclusion;
+import org.apache.maven.api.model.InputLocation;
+import org.apache.maven.api.model.InputLocationTracker;
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.model.Parent;
+import org.apache.maven.api.model.Plugin;
+import org.apache.maven.api.model.PluginExecution;
+import org.apache.maven.api.model.PluginManagement;
+import org.apache.maven.api.model.Profile;
+import org.apache.maven.api.model.ReportPlugin;
+import org.apache.maven.api.model.Reporting;
+import org.apache.maven.api.model.Repository;
+import org.apache.maven.api.model.Resource;
+import org.apache.maven.api.services.BuilderProblem.Severity;
+import org.apache.maven.api.services.ModelBuilderRequest;
+import org.apache.maven.api.services.ModelProblem.Version;
+import org.apache.maven.api.services.ModelProblemCollector;
+import org.apache.maven.api.services.model.*;
+import org.apache.maven.model.v4.MavenModelVersion;
+
+/**
+ */
+@Named
+@Singleton
+public class DefaultModelValidator implements ModelValidator {
+
+ public static final List<String> VALID_MODEL_VERSIONS =
+ Collections.unmodifiableList(Arrays.asList("4.0.0", "4.1.0"));
+
+ private static final Pattern EXPRESSION_NAME_PATTERN = Pattern.compile("\\$\\{(.+?)}");
+ private static final Pattern EXPRESSION_PROJECT_NAME_PATTERN = Pattern.compile("\\$\\{(project.+?)}");
+
+ private static final String ILLEGAL_FS_CHARS = "\\/:\"<>|?*";
+
+ private static final String ILLEGAL_VERSION_CHARS = ILLEGAL_FS_CHARS;
+
+ private static final String ILLEGAL_REPO_ID_CHARS = ILLEGAL_FS_CHARS;
+
+ private static final String EMPTY = "";
+
+ private final Set<String> validCoordinateIds = new HashSet<>();
+
+ private final Set<String> validProfileIds = new HashSet<>();
+
+ private final ModelVersionProcessor versionProcessor;
+
+ @Inject
+ public DefaultModelValidator(ModelVersionProcessor versionProcessor) {
+ this.versionProcessor = versionProcessor;
+ }
+
+ @Override
+ public void validateFileModel(Model m, ModelBuilderRequest request, ModelProblemCollector problems) {
+
+ Parent parent = m.getParent();
+ if (parent != null) {
+ validateStringNotEmpty(
+ "parent.groupId", problems, Severity.FATAL, Version.BASE, parent.getGroupId(), parent);
+
+ validateStringNotEmpty(
+ "parent.artifactId", problems, Severity.FATAL, Version.BASE, parent.getArtifactId(), parent);
+
+ if (equals(parent.getGroupId(), m.getGroupId()) && equals(parent.getArtifactId(), m.getArtifactId())) {
+ addViolation(
+ problems,
+ Severity.FATAL,
+ Version.BASE,
+ "parent.artifactId",
+ null,
+ "must be changed"
+ + ", the parent element cannot have the same groupId:artifactId as the project.",
+ parent);
+ }
+
+ if (equals("LATEST", parent.getVersion()) || equals("RELEASE", parent.getVersion())) {
+ addViolation(
+ problems,
+ Severity.WARNING,
+ Version.BASE,
+ "parent.version",
+ null,
+ "is either LATEST or RELEASE (both of them are being deprecated)",
+ parent);
+ }
+ }
+
+ if (request.getValidationLevel() >= ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_2_0) {
+ Set<String> modules = new HashSet<>();
+ for (int i = 0, n = m.getModules().size(); i < n; i++) {
+ String module = m.getModules().get(i);
+ if (!modules.add(module)) {
+ addViolation(
+ problems,
+ Severity.ERROR,
+ Version.V20,
+ "modules.module[" + i + "]",
+ null,
+ "specifies duplicate child module " + module,
+ m.getLocation("modules"));
+ }
+ }
+
+ Severity errOn30 = getSeverity(request, ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_0);
+
+ // The file pom may not contain the modelVersion yet, as it may be set later by the
+ // ModelVersionXMLFilter.
+ if (m.getModelVersion() != null && !m.getModelVersion().isEmpty()) {
+ validateModelVersion(problems, m.getModelVersion(), m, VALID_MODEL_VERSIONS);
+ }
+
+ validateStringNoExpression("groupId", problems, Severity.WARNING, Version.V20, m.getGroupId(), m);
+ if (parent == null) {
+ validateStringNotEmpty("groupId", problems, Severity.FATAL, Version.V20, m.getGroupId(), m);
+ }
+
+ validateStringNoExpression("artifactId", problems, Severity.WARNING, Version.V20, m.getArtifactId(), m);
+ validateStringNotEmpty("artifactId", problems, Severity.FATAL, Version.V20, m.getArtifactId(), m);
+
+ validateVersionNoExpression("version", problems, Severity.WARNING, Version.V20, m.getVersion(), m);
+ if (parent == null) {
+ validateStringNotEmpty("version", problems, Severity.FATAL, Version.V20, m.getVersion(), m);
+ }
+
+ validate20RawDependencies(problems, m.getDependencies(), "dependencies.dependency.", EMPTY, request);
+
+ validate20RawDependenciesSelfReferencing(
+ problems, m, m.getDependencies(), "dependencies.dependency", request);
+
+ if (m.getDependencyManagement() != null) {
+ validate20RawDependencies(
+ problems,
+ m.getDependencyManagement().getDependencies(),
+ "dependencyManagement.dependencies.dependency.",
+ EMPTY,
+ request);
+ }
+
+ validateRawRepositories(problems, m.getRepositories(), "repositories.repository.", EMPTY, request);
+
+ validateRawRepositories(
+ problems, m.getPluginRepositories(), "pluginRepositories.pluginRepository.", EMPTY, request);
+
+ Build build = m.getBuild();
+ if (build != null) {
+ validate20RawPlugins(problems, build.getPlugins(), "build.plugins.plugin.", EMPTY, request);
+
+ PluginManagement mgmt = build.getPluginManagement();
+ if (mgmt != null) {
+ validate20RawPlugins(
+ problems, mgmt.getPlugins(), "build.pluginManagement.plugins.plugin.", EMPTY, request);
+ }
+ }
+
+ Set<String> profileIds = new HashSet<>();
+
+ for (Profile profile : m.getProfiles()) {
+ String prefix = "profiles.profile[" + profile.getId() + "].";
+
+ validateProfileId(prefix, "id", problems, Severity.ERROR, Version.V40, profile.getId(), null, m);
+
+ if (!profileIds.add(profile.getId())) {
+ addViolation(
+ problems,
+ errOn30,
+ Version.V20,
+ "profiles.profile.id",
+ null,
+ "must be unique but found duplicate profile with id " + profile.getId(),
+ profile);
+ }
+
+ validate30RawProfileActivation(problems, profile.getActivation(), prefix);
+
+ validate20RawDependencies(
+ problems, profile.getDependencies(), prefix, "dependencies.dependency.", request);
+
+ if (profile.getDependencyManagement() != null) {
+ validate20RawDependencies(
+ problems,
+ profile.getDependencyManagement().getDependencies(),
+ prefix,
+ "dependencyManagement.dependencies.dependency.",
+ request);
+ }
+
+ validateRawRepositories(
+ problems, profile.getRepositories(), prefix, "repositories.repository.", request);
+
+ validateRawRepositories(
+ problems,
+ profile.getPluginRepositories(),
+ prefix,
+ "pluginRepositories.pluginRepository.",
+ request);
+
+ BuildBase buildBase = profile.getBuild();
+ if (buildBase != null) {
+ validate20RawPlugins(problems, buildBase.getPlugins(), prefix, "plugins.plugin.", request);
+
+ PluginManagement mgmt = buildBase.getPluginManagement();
+ if (mgmt != null) {
+ validate20RawPlugins(
+ problems, mgmt.getPlugins(), prefix, "pluginManagement.plugins.plugin.", request);
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void validateRawModel(Model m, ModelBuilderRequest request, ModelProblemCollector problems) {
+ // [MNG-6074] Maven should produce an error if no model version has been set in a POM file used to build an
+ // effective model.
+ //
+ // As of 3.4, the model version is mandatory even in raw models. The XML element still is optional in the
+ // XML schema and this will not change anytime soon. We do not want to build effective models based on
+ // models without a version starting with 3.4.
+ validateStringNotEmpty("modelVersion", problems, Severity.ERROR, Version.V20, m.getModelVersion(), m);
+
+ validateModelVersion(problems, m.getModelVersion(), m, VALID_MODEL_VERSIONS);
+
+ String minVersion = new MavenModelVersion().getModelVersion(m);
+ if (m.getModelVersion() != null && compareModelVersions(minVersion, m.getModelVersion()) > 0) {
+ addViolation(
+ problems,
+ Severity.FATAL,
+ Version.V40,
+ "model",
+ null,
+ "the model contains elements that require a model version of " + minVersion,
+ m);
+ }
+
+ Parent parent = m.getParent();
+
+ if (parent != null) {
+ validateStringNotEmpty(
+ "parent.version", problems, Severity.FATAL, Version.BASE, parent.getVersion(), parent);
+ }
+ }
+
+ private void validate30RawProfileActivation(ModelProblemCollector problems, Activation activation, String prefix) {
+ if (activation == null || activation.getFile() == null) {
+ return;
+ }
+
+ ActivationFile file = activation.getFile();
+
+ String path;
+ String location;
+
+ if (file.getExists() != null && !file.getExists().isEmpty()) {
+ path = file.getExists();
+ location = "exists";
+ } else if (file.getMissing() != null && !file.getMissing().isEmpty()) {
+ path = file.getMissing();
+ location = "missing";
+ } else {
+ return;
+ }
+
+ if (hasProjectExpression(path)) {
+ Matcher matcher = EXPRESSION_PROJECT_NAME_PATTERN.matcher(path);
+ while (matcher.find()) {
+ String propertyName = matcher.group(0);
+ if (!"${project.basedir}".equals(propertyName)) {
+ addViolation(
+ problems,
+ Severity.WARNING,
+ Version.V30,
+ prefix + "activation.file." + location,
+ null,
+ "Failed to interpolate file location " + path + ": " + propertyName
+ + " expressions are not supported during profile activation.",
+ file.getLocation(location));
+ }
+ }
+ }
+ }
+
+ private void validate20RawPlugins(
+ ModelProblemCollector problems,
+ List<Plugin> plugins,
+ String prefix,
+ String prefix2,
+ ModelBuilderRequest request) {
+ Severity errOn31 = getSeverity(request, ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_1);
+
+ Map<String, Plugin> index = new HashMap<>();
+
+ for (Plugin plugin : plugins) {
+ if (plugin.getGroupId() == null
+ || (plugin.getGroupId() != null
+ && plugin.getGroupId().trim().isEmpty())) {
+ addViolation(
+ problems,
+ Severity.FATAL,
+ Version.V20,
+ prefix + prefix2 + "(groupId:artifactId)",
+ null,
+ "groupId of a plugin must be defined. ",
+ plugin);
+ }
+
+ if (plugin.getArtifactId() == null
+ || (plugin.getArtifactId() != null
+ && plugin.getArtifactId().trim().isEmpty())) {
+ addViolation(
+ problems,
+ Severity.FATAL,
+ Version.V20,
+ prefix + prefix2 + "(groupId:artifactId)",
+ null,
+ "artifactId of a plugin must be defined. ",
+ plugin);
+ }
+
+ // This will catch cases like <version></version> or <version/>
+ if (plugin.getVersion() != null && plugin.getVersion().trim().isEmpty()) {
+ addViolation(
+ problems,
+ Severity.FATAL,
+ Version.V20,
+ prefix + prefix2 + "(groupId:artifactId)",
+ null,
+ "version of a plugin must be defined. ",
+ plugin);
+ }
+
+ String key = plugin.getKey();
+
+ Plugin existing = index.get(key);
+
+ if (existing != null) {
+ addViolation(
+ problems,
+ errOn31,
+ Version.V20,
+ prefix + prefix2 + "(groupId:artifactId)",
+ null,
+ "must be unique but found duplicate declaration of plugin " + key,
+ plugin);
+ } else {
+ index.put(key, plugin);
+ }
+
+ Set<String> executionIds = new HashSet<>();
+
+ for (PluginExecution exec : plugin.getExecutions()) {
+ if (!executionIds.add(exec.getId())) {
+ addViolation(
+ problems,
+ Severity.ERROR,
+ Version.V20,
+ prefix + prefix2 + "[" + plugin.getKey() + "].executions.execution.id",
+ null,
+ "must be unique but found duplicate execution with id " + exec.getId(),
+ exec);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void validateEffectiveModel(Model m, ModelBuilderRequest request, ModelProblemCollector problems) {
+ validateStringNotEmpty("modelVersion", problems, Severity.ERROR, Version.BASE, m.getModelVersion(), m);
+
+ validateCoordinateId("groupId", problems, m.getGroupId(), m);
+
+ validateCoordinateId("artifactId", problems, m.getArtifactId(), m);
+
+ validateStringNotEmpty("packaging", problems, Severity.ERROR, Version.BASE, m.getPackaging(), m);
+
+ if (!m.getModules().isEmpty()) {
+ if (!"pom".equals(m.getPackaging())) {
+ addViolation(
+ problems,
+ Severity.ERROR,
+ Version.BASE,
+ "packaging",
+ null,
+ "with value '" + m.getPackaging() + "' is invalid. Aggregator projects "
+ + "require 'pom' as packaging.",
+ m);
+ }
+
+ for (int i = 0, n = m.getModules().size(); i < n; i++) {
+ String module = m.getModules().get(i);
+
+ boolean isBlankModule = true;
+ if (module != null) {
+ for (int j = 0; j < module.length(); j++) {
+ if (!Character.isWhitespace(module.charAt(j))) {
+ isBlankModule = false;
+ }
+ }
+ }
+
+ if (isBlankModule) {
+ addViolation(
+ problems,
+ Severity.ERROR,
+ Version.BASE,
+ "modules.module[" + i + "]",
+ null,
+ "has been specified without a path to the project directory.",
+ m.getLocation("modules"));
+ }
+ }
+ }
+
+ validateStringNotEmpty("version", problems, Severity.ERROR, Version.BASE, m.getVersion(), m);
+
+ Severity errOn30 = getSeverity(request, ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_0);
+
+ validateEffectiveDependencies(problems, m, m.getDependencies(), false, request);
+
+ DependencyManagement mgmt = m.getDependencyManagement();
+ if (mgmt != null) {
+ validateEffectiveDependencies(problems, m, mgmt.getDependencies(), true, request);
+ }
+
+ if (request.getValidationLevel() >= ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_2_0) {
+ Severity errOn31 = getSeverity(request, ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_1);
+
+ validateBannedCharacters(
+ EMPTY, "version", problems, errOn31, Version.V20, m.getVersion(), null, m, ILLEGAL_VERSION_CHARS);
+ validate20ProperSnapshotVersion("version", problems, errOn31, Version.V20, m.getVersion(), null, m);
+
+ Build build = m.getBuild();
+ if (build != null) {
+ for (Plugin p : build.getPlugins()) {
+ validateStringNotEmpty(
+ "build.plugins.plugin.artifactId",
+ problems,
+ Severity.ERROR,
+ Version.V20,
+ p.getArtifactId(),
+ p);
+
+ validateStringNotEmpty(
+ "build.plugins.plugin.groupId", problems, Severity.ERROR, Version.V20, p.getGroupId(), p);
+
+ validate20PluginVersion(
+ "build.plugins.plugin.version", problems, p.getVersion(), p.getKey(), p, request);
+
+ validateBoolean(
+ "build.plugins.plugin.inherited",
+ EMPTY,
+ problems,
+ errOn30,
+ Version.V20,
+ p.getInherited(),
+ p.getKey(),
+ p);
+
+ validateBoolean(
+ "build.plugins.plugin.extensions",
+ EMPTY,
+ problems,
+ errOn30,
+ Version.V20,
+ p.getExtensions(),
+ p.getKey(),
+ p);
+
+ validate20EffectivePluginDependencies(problems, p, request);
+ }
+
+ validate20RawResources(problems, build.getResources(), "build.resources.resource.", request);
+
+ validate20RawResources(
+ problems, build.getTestResources(), "build.testResources.testResource.", request);
+ }
+
+ Reporting reporting = m.getReporting();
+ if (reporting != null) {
+ for (ReportPlugin p : reporting.getPlugins()) {
+ validateStringNotEmpty(
+ "reporting.plugins.plugin.artifactId",
+ problems,
+ Severity.ERROR,
+ Version.V20,
+ p.getArtifactId(),
+ p);
+
+ validateStringNotEmpty(
+ "reporting.plugins.plugin.groupId",
+ problems,
+ Severity.ERROR,
+ Version.V20,
+ p.getGroupId(),
+ p);
+ }
+ }
+
+ for (Repository repository : m.getRepositories()) {
+ validate20EffectiveRepository(problems, repository, "repositories.repository.", request);
+ }
+
+ for (Repository repository : m.getPluginRepositories()) {
+ validate20EffectiveRepository(problems, repository, "pluginRepositories.pluginRepository.", request);
+ }
+
+ DistributionManagement distMgmt = m.getDistributionManagement();
+ if (distMgmt != null) {
+ if (distMgmt.getStatus() != null) {
+ addViolation(
+ problems,
+ Severity.ERROR,
+ Version.V20,
+ "distributionManagement.status",
+ null,
+ "must not be specified.",
+ distMgmt);
+ }
+
+ validate20EffectiveRepository(
+ problems, distMgmt.getRepository(), "distributionManagement.repository.", request);
+ validate20EffectiveRepository(
+ problems,
+ distMgmt.getSnapshotRepository(),
+ "distributionManagement.snapshotRepository.",
+ request);
+ }
+ }
+ }
+
+ private void validate20RawDependencies(
+ ModelProblemCollector problems,
+ List<Dependency> dependencies,
+ String prefix,
+ String prefix2,
+ ModelBuilderRequest request) {
+ Severity errOn30 = getSeverity(request, ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_0);
+ Severity errOn31 = getSeverity(request, ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_1);
+
+ Map<String, Dependency> index = new HashMap<>();
+
+ for (Dependency dependency : dependencies) {
+ String key = dependency.getManagementKey();
+
+ if ("import".equals(dependency.getScope())) {
+ if (!"pom".equals(dependency.getType())) {
+ addViolation(
+ problems,
+ Severity.WARNING,
+ Version.V20,
+ prefix + prefix2 + "type",
+ key,
+ "must be 'pom' to import the managed dependencies.",
+ dependency);
+ } else if (dependency.getClassifier() != null
+ && !dependency.getClassifier().isEmpty()) {
+ addViolation(
+ problems,
+ errOn30,
+ Version.V20,
+ prefix + prefix2 + "classifier",
+ key,
+ "must be empty, imported POM cannot have a classifier.",
+ dependency);
+ }
+ } else if ("system".equals(dependency.getScope())) {
+
+ if (request.getValidationLevel() >= ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_1) {
+ addViolation(
+ problems,
+ Severity.WARNING,
+ Version.V31,
+ prefix + prefix2 + "scope",
+ key,
+ "declares usage of deprecated 'system' scope ",
+ dependency);
+ }
+
+ String sysPath = dependency.getSystemPath();
+ if (sysPath != null && !sysPath.isEmpty()) {
+ if (!hasExpression(sysPath)) {
+ addViolation(
+ problems,
+ Severity.WARNING,
+ Version.V20,
+ prefix + prefix2 + "systemPath",
+ key,
+ "should use a variable instead of a hard-coded path " + sysPath,
+ dependency);
+ } else if (sysPath.contains("${basedir}") || sysPath.contains("${project.basedir}")) {
+ addViolation(
+ problems,
+ Severity.WARNING,
+ Version.V20,
+ prefix + prefix2 + "systemPath",
+ key,
+ "should not point at files within the project directory, " + sysPath
+ + " will be unresolvable by dependent projects",
+ dependency);
+ }
+ }
+ }
+
+ if (equals("LATEST", dependency.getVersion()) || equals("RELEASE", dependency.getVersion())) {
+ addViolation(
+ problems,
+ Severity.WARNING,
+ Version.BASE,
+ prefix + prefix2 + "version",
+ key,
+ "is either LATEST or RELEASE (both of them are being deprecated)",
+ dependency);
+ }
+
+ Dependency existing = index.get(key);
+
+ if (existing != null) {
+ String msg;
+ if (equals(existing.getVersion(), dependency.getVersion())) {
+ msg = "duplicate declaration of version " + Objects.toString(dependency.getVersion(), "(?)");
+ } else {
+ msg = "version " + Objects.toString(existing.getVersion(), "(?)") + " vs "
+ + Objects.toString(dependency.getVersion(), "(?)");
+ }
+
+ addViolation(
+ problems,
+ errOn31,
+ Version.V20,
+ prefix + prefix2 + "(groupId:artifactId:type:classifier)",
+ null,
+ "must be unique: " + key + " -> " + msg,
+ dependency);
+ } else {
+ index.put(key, dependency);
+ }
+ }
+ }
+
+ private void validate20RawDependenciesSelfReferencing(
+ ModelProblemCollector problems,
+ org.apache.maven.api.model.Model m,
+ List<Dependency> dependencies,
+ String prefix,
+ ModelBuilderRequest request) {
+ // We only check for groupId/artifactId/version/classifier cause if there is another
+ // module with the same groupId/artifactId/version/classifier this will fail the build
+ // earlier like "Project '...' is duplicated in the reactor.
+ // So it is sufficient to check only groupId/artifactId/version/classifier and not the
+ // packaging type.
+ for (Dependency dependency : dependencies) {
+ String key = dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion()
+ + (dependency.getClassifier() != null ? ":" + dependency.getClassifier() : EMPTY);
+ String mKey = m.getGroupId() + ":" + m.getArtifactId() + ":" + m.getVersion();
+ if (key.equals(mKey)) {
+ // This means a module which is build has a dependency which has the same
+ // groupId, artifactId, version and classifier coordinates. This is in consequence
+ // a self reference or in other words a circular reference which can not being resolved.
+ addViolation(
+ problems,
+ Severity.FATAL,
+ Version.V31,
+ prefix + "[" + key + "]",
+ key,
+ "is referencing itself.",
+ dependency);
+ }
+ }
+ }
+
+ private void validateEffectiveDependencies(
+ ModelProblemCollector problems,
+ org.apache.maven.api.model.Model m,
+ List<Dependency> dependencies,
+ boolean management,
+ ModelBuilderRequest request) {
+ Severity errOn30 = getSeverity(request, ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_0);
+
+ String prefix = management ? "dependencyManagement.dependencies.dependency." : "dependencies.dependency.";
+
+ for (Dependency d : dependencies) {
+ validateEffectiveDependency(problems, d, management, prefix, request);
+
+ if (request.getValidationLevel() >= ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_2_0) {
+ validateBoolean(
+ prefix, "optional", problems, errOn30, Version.V20, d.getOptional(), d.getManagementKey(), d);
+
+ if (!management) {
+ validateVersion(
+ prefix, "version", problems, errOn30, Version.V20, d.getVersion(), d.getManagementKey(), d);
+
+ /*
+ * TODO Extensions like Flex Mojos use custom scopes like "merged", "internal", "external", etc. In
+ * order to don't break backward-compat with those, only warn but don't error out.
+ */
+ validateEnum(
+ prefix,
+ "scope",
+ problems,
+ Severity.WARNING,
+ Version.V20,
+ d.getScope(),
+ d.getManagementKey(),
+ d,
+ "provided",
+ "compile",
+ "runtime",
+ "test",
+ "system");
+
+ validateEffectiveModelAgainstDependency(prefix, problems, m, d, request);
+ } else {
+ validateEnum(
+ prefix,
+ "scope",
+ problems,
+ Severity.WARNING,
+ Version.V20,
+ d.getScope(),
+ d.getManagementKey(),
+ d,
+ "provided",
+ "compile",
+ "runtime",
+ "test",
+ "system",
+ "import");
+ }
+ }
+ }
+ }
+
+ private void validateEffectiveModelAgainstDependency(
+ String prefix,
+ ModelProblemCollector problems,
+ org.apache.maven.api.model.Model m,
+ Dependency d,
+ ModelBuilderRequest request) {
+ String key = d.getGroupId() + ":" + d.getArtifactId() + ":" + d.getVersion()
+ + (d.getClassifier() != null ? ":" + d.getClassifier() : EMPTY);
+ String mKey = m.getGroupId() + ":" + m.getArtifactId() + ":" + m.getVersion();
+ if (key.equals(mKey)) {
+ // This means a module which is build has a dependency which has the same
+ // groupId, artifactId, version and classifier coordinates. This is in consequence
+ // a self reference or in other words a circular reference which can not being resolved.
+ addViolation(
+ problems, Severity.FATAL, Version.V31, prefix + "[" + key + "]", key, "is referencing itself.", d);
+ }
+ }
+
+ private void validate20EffectivePluginDependencies(
+ ModelProblemCollector problems, Plugin plugin, ModelBuilderRequest request) {
+ List<Dependency> dependencies = plugin.getDependencies();
+
+ if (!dependencies.isEmpty()) {
+ String prefix = "build.plugins.plugin[" + plugin.getKey() + "].dependencies.dependency.";
+
+ Severity errOn30 = getSeverity(request, ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_0);
+
+ for (Dependency d : dependencies) {
+ validateEffectiveDependency(problems, d, false, prefix, request);
+
+ validateVersion(
+ prefix, "version", problems, errOn30, Version.BASE, d.getVersion(), d.getManagementKey(), d);
+
+ validateEnum(
+ prefix,
+ "scope",
+ problems,
+ errOn30,
+ Version.BASE,
+ d.getScope(),
+ d.getManagementKey(),
+ d,
+ "compile",
+ "runtime",
+ "system");
+ }
+ }
+ }
+
+ private void validateEffectiveDependency(
+ ModelProblemCollector problems,
+ Dependency d,
+ boolean management,
+ String prefix,
+ ModelBuilderRequest request) {
+ validateCoordinateId(
+ prefix,
+ "artifactId",
+ problems,
+ Severity.ERROR,
+ Version.BASE,
+ d.getArtifactId(),
+ d.getManagementKey(),
+ d);
+
+ validateCoordinateId(
+ prefix, "groupId", problems, Severity.ERROR, Version.BASE, d.getGroupId(), d.getManagementKey(), d);
+
+ if (!management) {
+ validateStringNotEmpty(
+ prefix, "type", problems, Severity.ERROR, Version.BASE, d.getType(), d.getManagementKey(), d);
+
+ validateDependencyVersion(problems, d, prefix);
+ }
+
+ if ("system".equals(d.getScope())) {
+ String systemPath = d.getSystemPath();
+
+ if (systemPath == null || systemPath.isEmpty()) {
+ addViolation(
+ problems,
+ Severity.ERROR,
+ Version.BASE,
+ prefix + "systemPath",
+ d.getManagementKey(),
+ "is missing.",
+ d);
+ } else {
+ File sysFile = new File(systemPath);
+ if (!sysFile.isAbsolute()) {
+ addViolation(
+ problems,
+ Severity.ERROR,
+ Version.BASE,
+ prefix + "systemPath",
+ d.getManagementKey(),
+ "must specify an absolute path but is " + systemPath,
+ d);
+ } else if (!sysFile.isFile()) {
+ String msg = "refers to a non-existing file " + sysFile.getAbsolutePath();
+ systemPath = systemPath.replace('/', File.separatorChar).replace('\\', File.separatorChar);
+ String jdkHome = request.getSystemProperties().get("java.home") + File.separator + "..";
+ if (systemPath.startsWith(jdkHome)) {
+ msg += ". Please verify that you run Maven using a JDK and not just a JRE.";
+ }
+ addViolation(
+ problems,
+ Severity.WARNING,
+ Version.BASE,
+ prefix + "systemPath",
+ d.getManagementKey(),
+ msg,
+ d);
+ }
+ }
+ } else if (d.getSystemPath() != null && !d.getSystemPath().isEmpty()) {
+ addViolation(
+ problems,
+ Severity.ERROR,
+ Version.BASE,
+ prefix + "systemPath",
+ d.getManagementKey(),
+ "must be omitted. This field may only be specified for a dependency with system scope.",
+ d);
+ }
+
+ if (request.getValidationLevel() >= ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_2_0) {
+ for (Exclusion exclusion : d.getExclusions()) {
+ if (request.getValidationLevel() < ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_0) {
+ validateCoordinateId(
+ prefix,
+ "exclusions.exclusion.groupId",
+ problems,
+ Severity.WARNING,
+ Version.V20,
+ exclusion.getGroupId(),
+ d.getManagementKey(),
+ exclusion);
+
+ validateCoordinateId(
+ prefix,
+ "exclusions.exclusion.artifactId",
+ problems,
+ Severity.WARNING,
+ Version.V20,
+ exclusion.getArtifactId(),
+ d.getManagementKey(),
+ exclusion);
+ } else {
+ validateCoordinateIdWithWildcards(
+ prefix,
+ "exclusions.exclusion.groupId",
+ problems,
+ Severity.WARNING,
+ Version.V30,
+ exclusion.getGroupId(),
+ d.getManagementKey(),
+ exclusion);
+
+ validateCoordinateIdWithWildcards(
+ prefix,
+ "exclusions.exclusion.artifactId",
+ problems,
+ Severity.WARNING,
+ Version.V30,
+ exclusion.getArtifactId(),
+ d.getManagementKey(),
+ exclusion);
+ }
+ }
+ }
+ }
+
+ /**
+ * @since 3.2.4
+ */
+ protected void validateDependencyVersion(ModelProblemCollector problems, Dependency d, String prefix) {
+ validateStringNotEmpty(
+ prefix, "version", problems, Severity.ERROR, Version.BASE, d.getVersion(), d.getManagementKey(), d);
+ }
+
+ private void validateRawRepositories(
+ ModelProblemCollector problems,
+ List<Repository> repositories,
+ String prefix,
+ String prefix2,
+ ModelBuilderRequest request) {
+ Map<String, Repository> index = new HashMap<>();
+
+ for (Repository repository : repositories) {
+ validateStringNotEmpty(
+ prefix, prefix2, "id", problems, Severity.ERROR, Version.V20, repository.getId(), null, repository);
+
+ if (validateStringNotEmpty(
+ prefix,
+ prefix2,
+ "[" + repository.getId() + "].url",
+ problems,
+ Severity.ERROR,
+ Version.V20,
+ repository.getUrl(),
+ null,
+ repository)) {
+ // only allow ${basedir} and ${project.basedir}
+ Matcher m = EXPRESSION_NAME_PATTERN.matcher(repository.getUrl());
+ while (m.find()) {
+ if (!("basedir".equals(m.group(1)) || "project.basedir".equals(m.group(1)))) {
+ validateStringNoExpression(
+ prefix + prefix2 + "[" + repository.getId() + "].url",
+ problems,
+ Severity.ERROR,
+ Version.V40,
+ repository.getUrl(),
+ repository);
+ break;
+ }
+ }
+ }
+
+ String key = repository.getId();
+
+ Repository existing = index.get(key);
+
+ if (existing != null) {
+ Severity errOn30 = getSeverity(request, ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_0);
+
+ addViolation(
+ problems,
+ errOn30,
+ Version.V20,
+ prefix + prefix2 + "id",
+ null,
+ "must be unique: " + repository.getId() + " -> " + existing.getUrl() + " vs "
+ + repository.getUrl(),
+ repository);
+ } else {
+ index.put(key, repository);
+ }
+ }
+ }
+
+ private void validate20EffectiveRepository(
+ ModelProblemCollector problems, Repository repository, String prefix, ModelBuilderRequest request) {
+ if (repository != null) {
+ Severity errOn31 = getSeverity(request, ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_1);
+
+ validateBannedCharacters(
+ prefix,
+ "id",
+ problems,
+ errOn31,
+ Version.V20,
+ repository.getId(),
+ null,
+ repository,
+ ILLEGAL_REPO_ID_CHARS);
+
+ if ("local".equals(repository.getId())) {
+ addViolation(
+ problems,
+ errOn31,
+ Version.V20,
+ prefix + "id",
+ null,
+ "must not be 'local'" + ", this identifier is reserved for the local repository"
+ + ", using it for other repositories will corrupt your repository metadata.",
+ repository);
+ }
+
+ if ("legacy".equals(repository.getLayout())) {
+ addViolation(
+ problems,
+ Severity.WARNING,
+ Version.V20,
+ prefix + "layout",
+ repository.getId(),
+ "uses the unsupported value 'legacy', artifact resolution might fail.",
+ repository);
+ }
+ }
+ }
+
+ private void validate20RawResources(
+ ModelProblemCollector problems, List<Resource> resources, String prefix, ModelBuilderRequest request) {
+ Severity errOn30 = getSeverity(request, ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_3_0);
+
+ for (Resource resource : resources) {
+ validateStringNotEmpty(
+ prefix,
+ "directory",
+ problems,
+ Severity.ERROR,
+ Version.V20,
+ resource.getDirectory(),
+ null,
+ resource);
+
+ validateBoolean(
+ prefix,
+ "filtering",
+ problems,
+ errOn30,
+ Version.V20,
+ resource.getFiltering(),
+ resource.getDirectory(),
+ resource);
+ }
+ }
+
+ // ----------------------------------------------------------------------
+ // Field validation
+ // ----------------------------------------------------------------------
+
+ private boolean validateCoordinateId(
+ String fieldName, ModelProblemCollector problems, String id, InputLocationTracker tracker) {
+ return validateCoordinateId(EMPTY, fieldName, problems, Severity.ERROR, Version.BASE, id, null, tracker);
+ }
+
+ @SuppressWarnings("checkstyle:parameternumber")
+ private boolean validateCoordinateId(
+ String prefix,
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ String id,
+ String sourceHint,
+ InputLocationTracker tracker) {
+ if (validCoordinateIds.contains(id)) {
+ return true;
+ }
+ if (!validateStringNotEmpty(prefix, fieldName, problems, severity, version, id, sourceHint, tracker)) {
+ return false;
+ } else {
+ if (!isValidCoordinateId(id)) {
+ addViolation(
+ problems,
+ severity,
+ version,
+ prefix + fieldName,
+ sourceHint,
+ "with value '" + id + "' does not match a valid coordinate id pattern.",
+ tracker);
+ return false;
+ }
+ validCoordinateIds.add(id);
+ return true;
+ }
+ }
+
+ private boolean isValidCoordinateId(String id) {
+ for (int i = 0; i < id.length(); i++) {
+ char c = id.charAt(i);
+ if (!isValidCoordinateIdCharacter(c)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean isValidCoordinateIdCharacter(char c) {
+ return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '-' || c == '_' || c == '.';
+ }
+
+ @SuppressWarnings("checkstyle:parameternumber")
+ private boolean validateProfileId(
+ String prefix,
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ String id,
+ String sourceHint,
+ InputLocationTracker tracker) {
+ if (validProfileIds.contains(id)) {
+ return true;
+ }
+ if (!validateStringNotEmpty(prefix, fieldName, problems, severity, version, id, sourceHint, tracker)) {
+ return false;
+ } else {
+ if (!isValidProfileId(id)) {
+ addViolation(
+ problems,
+ severity,
+ version,
+ prefix + fieldName,
+ sourceHint,
+ "with value '" + id + "' does not match a valid profile id pattern.",
+ tracker);
+ return false;
+ }
+ validProfileIds.add(id);
+ return true;
+ }
+ }
+
+ private boolean isValidProfileId(String id) {
+ switch (id.charAt(0)) { // avoid first character that has special CLI meaning in "mvn -P xxx"
+ case '+': // activate
+ case '-': // deactivate
+ case '!': // deactivate
+ case '?': // optional
+ return false;
+ default:
+ }
+ return true;
+ }
+
+ @SuppressWarnings("checkstyle:parameternumber")
+ private boolean validateCoordinateIdWithWildcards(
+ String prefix,
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ String id,
+ String sourceHint,
+ InputLocationTracker tracker) {
+ if (!validateStringNotEmpty(prefix, fieldName, problems, severity, version, id, sourceHint, tracker)) {
+ return false;
+ } else {
+ if (!isValidCoordinateIdWithWildCards(id)) {
+ addViolation(
+ problems,
+ severity,
+ version,
+ prefix + fieldName,
+ sourceHint,
+ "with value '" + id + "' does not match a valid coordinate id pattern.",
+ tracker);
+ return false;
+ }
+ return true;
+ }
+ }
+
+ private boolean isValidCoordinateIdWithWildCards(String id) {
+ for (int i = 0; i < id.length(); i++) {
+ char c = id.charAt(i);
+ if (!isValidCoordinateIdWithWildCardCharacter(c)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean isValidCoordinateIdWithWildCardCharacter(char c) {
+ return isValidCoordinateIdCharacter(c) || c == '?' || c == '*';
+ }
+
+ private boolean validateStringNoExpression(
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ String string,
+ InputLocationTracker tracker) {
+ if (!hasExpression(string)) {
+ return true;
+ }
+
+ addViolation(
+ problems,
+ severity,
+ version,
+ fieldName,
+ null,
+ "contains an expression but should be a constant.",
+ tracker);
+
+ return false;
+ }
+
+ private boolean validateVersionNoExpression(
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ String string,
+ InputLocationTracker tracker) {
+ if (!hasExpression(string)) {
+ return true;
+ }
+
+ Matcher m = EXPRESSION_NAME_PATTERN.matcher(string.trim());
+ while (m.find()) {
+ String property = m.group(1);
+ if (!versionProcessor.isValidProperty(property)) {
+ addViolation(
+ problems,
+ severity,
+ version,
+ fieldName,
+ null,
+ "contains an expression but should be a constant.",
+ tracker);
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private boolean hasExpression(String value) {
+ return value != null && value.contains("${");
+ }
+
+ private boolean hasProjectExpression(String value) {
+ return value != null && value.contains("${project.");
+ }
+
+ private boolean validateStringNotEmpty(
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ String string,
+ InputLocationTracker tracker) {
+ return validateStringNotEmpty(EMPTY, fieldName, problems, severity, version, string, null, tracker);
+ }
+
+ /**
+ * Asserts:
+ * <p/>
+ * <ul>
+ * <li><code>string != null</code>
+ * <li><code>string.length > 0</code>
+ * </ul>
+ */
+ @SuppressWarnings("checkstyle:parameternumber")
+ private boolean validateStringNotEmpty(
+ String prefix,
+ String prefix2,
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ String string,
+ String sourceHint,
+ InputLocationTracker tracker) {
+ if (!validateNotNull(prefix, prefix2, fieldName, problems, severity, version, string, sourceHint, tracker)) {
+ return false;
+ }
+
+ if (!string.isEmpty()) {
+ return true;
+ }
+
+ addViolation(problems, severity, version, prefix + prefix2 + fieldName, sourceHint, "is missing.", tracker);
+
+ return false;
+ }
+
+ /**
+ * Asserts:
+ * <p/>
+ * <ul>
+ * <li><code>string != null</code>
+ * <li><code>string.length > 0</code>
+ * </ul>
+ */
+ @SuppressWarnings("checkstyle:parameternumber")
+ private boolean validateStringNotEmpty(
+ String prefix,
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ String string,
+ String sourceHint,
+ InputLocationTracker tracker) {
+ if (!validateNotNull(prefix, fieldName, problems, severity, version, string, sourceHint, tracker)) {
+ return false;
+ }
+
+ if (!string.isEmpty()) {
+ return true;
+ }
+
+ addViolation(problems, severity, version, prefix + fieldName, sourceHint, "is missing.", tracker);
+
+ return false;
+ }
+
+ /**
+ * Asserts:
+ * <p/>
+ * <ul>
+ * <li><code>string != null</code>
+ * </ul>
+ */
+ @SuppressWarnings("checkstyle:parameternumber")
+ private boolean validateNotNull(
+ String prefix,
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ Object object,
+ String sourceHint,
+ InputLocationTracker tracker) {
+ if (object != null) {
+ return true;
+ }
+
+ addViolation(problems, severity, version, prefix + fieldName, sourceHint, "is missing.", tracker);
+
+ return false;
+ }
+
+ /**
+ * Asserts:
+ * <p/>
+ * <ul>
+ * <li><code>string != null</code>
+ * </ul>
+ */
+ @SuppressWarnings("checkstyle:parameternumber")
+ private boolean validateNotNull(
+ String prefix,
+ String prefix2,
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ Object object,
+ String sourceHint,
+ InputLocationTracker tracker) {
+ if (object != null) {
+ return true;
+ }
+
+ addViolation(problems, severity, version, prefix + prefix2 + fieldName, sourceHint, "is missing.", tracker);
+
+ return false;
+ }
+
+ @SuppressWarnings("checkstyle:parameternumber")
+ private boolean validateBoolean(
+ String prefix,
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ String string,
+ String sourceHint,
+ InputLocationTracker tracker) {
+ if (string == null || string.isEmpty()) {
+ return true;
+ }
+
+ if ("true".equalsIgnoreCase(string) || "false".equalsIgnoreCase(string)) {
+ return true;
+ }
+
+ addViolation(
+ problems,
+ severity,
+ version,
+ prefix + fieldName,
+ sourceHint,
+ "must be 'true' or 'false' but is '" + string + "'.",
+ tracker);
+
+ return false;
+ }
+
+ @SuppressWarnings("checkstyle:parameternumber")
+ private boolean validateEnum(
+ String prefix,
+ String fieldName,
+ ModelProblemCollector problems,
+ Severity severity,
+ Version version,
+ String string,
+ String sourceHint,
+ InputLocationTracker tracker,
+ String... validValues) {
+ if (string == null || string.isEmpty()) {
+ return true;
+ }
+
+ List<String> values = Arrays.asList(validValues);
+
+ if (values.contains(string)) {
+ return true;
+ }
+
+ addViolation(
+ problems,
+ severity,
+ version,
+ prefix + fieldName,
+ sourceHint,
+ "must be one of " + values + " but is '" + string + "'.",
+ tracker);
+
+ return false;
+ }
+
+ @SuppressWarnings("checkstyle:parameternumber")
+ private boolean validateModelVersion(
+ ModelProblemCollector problems, String string, InputLocationTracker tracker, List<String> validVersions) {
+ if (string == null || string.isEmpty()) {
+ return true;
+ }
+
+ if (validVersions.contains(string)) {
+ return true;
+ }
+
+ boolean newerThanAll = true;
+ boolean olderThanAll = true;
+ for (String validValue : validVersions) {
+ final int comparison = compareModelVersions(validValue, string);
+ newerThanAll = newerThanAll && comparison < 0;
... 12060 lines suppressed ...
(maven) 01/02: [MNG-8084] Include lifecycle in the API
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 9be08ccef8d6c59867f49ecb98e772776fc8f9c0
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Apr 11 08:17:32 2024 +0200
[MNG-8084] Include lifecycle in the API
---
.../api/{MetadataStorage.java => Lifecycle.java} | 50 ++++-
.../main/java/org/apache/maven/api/PathScope.java | 1 +
.../maven/api/plugin/annotations/Execute.java | 13 +-
.../api/plugin/annotations/LifecyclePhase.java | 74 -------
.../apache/maven/api/plugin/annotations/Mojo.java | 2 +-
.../maven/api/services/LifecycleRegistry.java | 34 +--
.../apache/maven/api/spi/LifecycleProvider.java} | 16 +-
.../internal/impl/DefaultLifecycleRegistry.java | 227 +++++++++++++++++++++
.../internal/impl/ExtensibleEnumRegistries.java | 9 +-
.../java/org/apache/maven/internal/impl/Graph.java | 145 +++++++++++++
.../org/apache/maven/internal/impl/Lifecycles.java | 73 +++++++
.../apache/maven/lifecycle/DefaultLifecycles.java | 16 +-
.../java/org/apache/maven/lifecycle/Lifecycle.java | 29 ++-
.../providers/CleanLifecycleProvider.java | 47 -----
.../providers/DefaultLifecycleProvider.java | 70 -------
.../lifecycle/providers/SiteLifecycleProvider.java | 48 -----
.../maven/lifecycle/DefaultLifecyclesTest.java | 5 +-
.../internal/stub/DefaultLifecyclesStub.java | 4 +-
18 files changed, 559 insertions(+), 304 deletions(-)
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java b/api/maven-api-core/src/main/java/org/apache/maven/api/Lifecycle.java
similarity index 50%
copy from api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java
copy to api/maven-api-core/src/main/java/org/apache/maven/api/Lifecycle.java
index a7b8075ada..c461ef0ad0 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Lifecycle.java
@@ -18,16 +18,56 @@
*/
package org.apache.maven.api;
+import java.util.*;
+
import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.annotations.Immutable;
+import org.apache.maven.api.model.Plugin;
/**
- * Storage location for metadata
+ * Lifecycle definition
*
* @since 4.0.0
*/
@Experimental
-public enum MetadataStorage {
- GROUP,
- ARTIFACT,
- VERSION
+@Immutable
+public interface Lifecycle extends ExtensibleEnum {
+
+ String CLEAN = "clean";
+
+ String DEFAULT = "default";
+
+ String SITE = "site";
+
+ String WRAPPER = "wrapper";
+
+ /**
+ * Name or identifier of this lifecycle.
+ *
+ * @return the unique identifier for this lifecycle
+ */
+ @Override
+ String id();
+
+ /**
+ * Collection of phases for this lifecycle
+ */
+ Collection<Phase> phases();
+
+ /**
+ * Pre-ordered list of phases.
+ * If not provided, a default order will be computed.
+ */
+ default Optional<List<String>> orderedPhases() {
+ return Optional.empty();
+ }
+
+ /**
+ * A phase in the lifecycle.
+ */
+ interface Phase {
+ String name();
+
+ List<Plugin> plugins();
+ }
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/PathScope.java b/api/maven-api-core/src/main/java/org/apache/maven/api/PathScope.java
index 93b1c90545..b32dd3c172 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/PathScope.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/PathScope.java
@@ -46,6 +46,7 @@ import static org.apache.maven.api.ExtensibleEnums.pathScope;
@Immutable
public interface PathScope extends ExtensibleEnum {
+ // TODO: what if I simply want all dependencies ?
@Nonnull
ProjectScope projectScope();
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/Execute.java b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/Execute.java
index 903d224f38..f4830b87ae 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/Execute.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/Execute.java
@@ -41,21 +41,10 @@ import org.apache.maven.api.annotations.Nonnull;
public @interface Execute {
/**
* Lifecycle phase to fork. Note that specifying a phase overrides specifying a goal.
- * For custom lifecycle phase ids use {@link #customPhase()} instead.
- * Only one of {@link #customPhase()} and {@link #phase()} must be set.
* @return the phase
*/
@Nonnull
- LifecyclePhase phase() default LifecyclePhase.NONE;
-
- /**
- * Custom lifecycle phase to fork. Note that specifying a phase overrides specifying a goal.
- * This element should only be used for non-standard phases. For standard phases rather use {@link #phase()}.
- * Only one of {@link #customPhase()} and {@link #phase()} must be set.
- * @return the custom phase id
- */
- @Nonnull
- String customPhase() default "";
+ String phase() default "";
/**
* Goal to fork. Note that specifying a phase overrides specifying a goal. The specified <code>goal</code> must be
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/LifecyclePhase.java b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/LifecyclePhase.java
deleted file mode 100644
index b3ddb72f38..0000000000
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/LifecyclePhase.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.api.plugin.annotations;
-
-import org.apache.maven.api.annotations.Experimental;
-
-/**
- * <a href="/ref/3.0.4/maven-core/lifecycles.html">Lifecycle phases</a>.
- *
- * @since 4.0.0
- */
-@Experimental
-public enum LifecyclePhase {
- VALIDATE("validate"),
- INITIALIZE("initialize"),
- GENERATE_SOURCES("generate-sources"),
- PROCESS_SOURCES("process-sources"),
- GENERATE_RESOURCES("generate-resources"),
- PROCESS_RESOURCES("process-resources"),
- COMPILE("compile"),
- PROCESS_CLASSES("process-classes"),
- GENERATE_TEST_SOURCES("generate-test-sources"),
- PROCESS_TEST_SOURCES("process-test-sources"),
- GENERATE_TEST_RESOURCES("generate-test-resources"),
- PROCESS_TEST_RESOURCES("process-test-resources"),
- TEST_COMPILE("test-compile"),
- PROCESS_TEST_CLASSES("process-test-classes"),
- TEST("test"),
- PREPARE_PACKAGE("prepare-package"),
- PACKAGE("package"),
- PRE_INTEGRATION_TEST("pre-integration-test"),
- INTEGRATION_TEST("integration-test"),
- POST_INTEGRATION_TEST("post-integration-test"),
- VERIFY("verify"),
- INSTALL("install"),
- DEPLOY("deploy"),
-
- PRE_CLEAN("pre-clean"),
- CLEAN("clean"),
- POST_CLEAN("post-clean"),
-
- PRE_SITE("pre-site"),
- SITE("site"),
- POST_SITE("post-site"),
- SITE_DEPLOY("site-deploy"),
-
- NONE("");
-
- private final String id;
-
- LifecyclePhase(String id) {
- this.id = id;
- }
-
- public String id() {
- return this.id;
- }
-}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/Mojo.java b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/Mojo.java
index 4f01f0f6d2..a5768dfb4a 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/Mojo.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/Mojo.java
@@ -54,7 +54,7 @@ public @interface Mojo {
* @return the default phase
*/
@Nonnull
- LifecyclePhase defaultPhase() default LifecyclePhase.NONE;
+ String defaultPhase() default "";
/**
* does your mojo requires a project to be executed?
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/WrapperLifecycleProvider.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/LifecycleRegistry.java
similarity index 50%
rename from maven-core/src/main/java/org/apache/maven/lifecycle/providers/WrapperLifecycleProvider.java
rename to api/maven-api-core/src/main/java/org/apache/maven/api/services/LifecycleRegistry.java
index 29ddaea043..2718582a24 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/WrapperLifecycleProvider.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/LifecycleRegistry.java
@@ -16,32 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.lifecycle.providers;
+package org.apache.maven.api.services;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
+import java.util.List;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
-/**
- * {@code wrapper} lifecycle provider.
- */
-@Named(WrapperLifecycleProvider.LIFECYCLE_ID)
-@Singleton
-public final class WrapperLifecycleProvider extends AbstractLifecycleProvider {
- static final String LIFECYCLE_ID = "wrapper";
-
- // START SNIPPET: wrapper
- private static final String[] PHASES = {"wrapper"};
-
- private static final String MAVEN_WRAPPER_PLUGIN_VERSION = "3.2.0";
+import org.apache.maven.api.Lifecycle;
- private static final String[] BINDINGS = {
- "wrapper", "org.apache.maven.plugins:maven-wrapper-plugin:" + MAVEN_WRAPPER_PLUGIN_VERSION + ":wrapper"
- };
- // END SNIPPET: wrapper
-
- @Inject
- public WrapperLifecycleProvider() {
- super(LIFECYCLE_ID, PHASES, BINDINGS);
+public interface LifecycleRegistry extends ExtensibleEnumRegistry<Lifecycle>, Iterable<Lifecycle> {
+ default Stream<Lifecycle> stream() {
+ return StreamSupport.stream(spliterator(), false);
}
+
+ List<String> computePhases(Lifecycle lifecycle);
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java b/api/maven-api-spi/src/main/java/org/apache/maven/api/spi/LifecycleProvider.java
similarity index 80%
rename from api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java
rename to api/maven-api-spi/src/main/java/org/apache/maven/api/spi/LifecycleProvider.java
index a7b8075ada..539c628299 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/MetadataStorage.java
+++ b/api/maven-api-spi/src/main/java/org/apache/maven/api/spi/LifecycleProvider.java
@@ -16,18 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api;
+package org.apache.maven.api.spi;
+import org.apache.maven.api.Lifecycle;
+import org.apache.maven.api.annotations.Consumer;
import org.apache.maven.api.annotations.Experimental;
-/**
- * Storage location for metadata
- *
- * @since 4.0.0
- */
@Experimental
-public enum MetadataStorage {
- GROUP,
- ARTIFACT,
- VERSION
-}
+@Consumer
+public interface LifecycleProvider extends ExtensibleEnumProvider<Lifecycle> {}
diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java
new file mode 100644
index 0000000000..776f8d8a27
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java
@@ -0,0 +1,227 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.Lifecycle;
+import org.apache.maven.api.services.LifecycleRegistry;
+import org.apache.maven.api.spi.LifecycleProvider;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.*;
+import static org.apache.maven.internal.impl.Lifecycles.*;
+
+/**
+ * TODO: this is session scoped as SPI can contribute.
+ */
+@Named
+@Singleton
+public class DefaultLifecycleRegistry
+ extends ExtensibleEnumRegistries.DefaultExtensibleEnumRegistry<Lifecycle, LifecycleProvider>
+ implements LifecycleRegistry {
+
+ public DefaultLifecycleRegistry() {
+ super(Collections.emptyList());
+ }
+
+ @Inject
+ public DefaultLifecycleRegistry(
+ List<LifecycleProvider> providers, Map<String, org.apache.maven.lifecycle.Lifecycle> lifecycles) {
+ super(
+ concat(providers, new LifecycleWrapperProvider(lifecycles)),
+ new CleanLifecycle(),
+ new DefaultLifecycle(),
+ new SiteLifecycle(),
+ new WrapperLifecycle());
+ // validate lifecycle
+ for (Lifecycle lifecycle : this) {
+ Set<String> set = new HashSet<>();
+ lifecycle.phases().forEach(phase -> {
+ if (!set.add(phase.name())) {
+ throw new IllegalArgumentException(
+ "Found duplicated phase '" + phase.name() + "' in '" + lifecycle.id() + "' lifecycle");
+ }
+ });
+ }
+ }
+
+ @Override
+ public Iterator<Lifecycle> iterator() {
+ return values.values().iterator();
+ }
+
+ @Override
+ public Stream<Lifecycle> stream() {
+ return values.values().stream();
+ }
+
+ static <T> List<T> concat(List<T> l, T t) {
+ List<T> nl = new ArrayList<>(l.size() + 1);
+ nl.addAll(l);
+ nl.add(t);
+ return nl;
+ }
+
+ @Override
+ public List<String> computePhases(Lifecycle lifecycle) {
+ return lifecycle.phases().stream().map(Lifecycle.Phase::name).toList();
+ }
+
+ static class LifecycleWrapperProvider implements LifecycleProvider {
+ private final Map<String, org.apache.maven.lifecycle.Lifecycle> lifecycles;
+
+ @Inject
+ LifecycleWrapperProvider(Map<String, org.apache.maven.lifecycle.Lifecycle> lifecycles) {
+ this.lifecycles = lifecycles;
+ }
+
+ @Override
+ public Collection<Lifecycle> provides() {
+ return lifecycles.values().stream().map(this::wrap).collect(Collectors.toList());
+ }
+
+ private Lifecycle wrap(org.apache.maven.lifecycle.Lifecycle lifecycle) {
+ return new Lifecycle() {
+ @Override
+ public String id() {
+ return lifecycle.getId();
+ }
+
+ @Override
+ public Collection<Phase> phases() {
+ // TODO: implement
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+ }
+
+ static class CleanLifecycle implements Lifecycle {
+
+ private static final String MAVEN_CLEAN_PLUGIN_VERSION = "3.2.0";
+
+ @Override
+ public String id() {
+ return Lifecycle.CLEAN;
+ }
+
+ @Override
+ public Collection<Phase> phases() {
+ return asList(
+ phase("pre-clean"),
+ phase(
+ "clean",
+ plugin(
+ "org.apache.maven.plugins:maven-clean-plugin:" + MAVEN_CLEAN_PLUGIN_VERSION
+ + ":clean",
+ "clean")),
+ phase("post-clean"));
+ }
+ }
+
+ static class DefaultLifecycle implements Lifecycle {
+ @Override
+ public String id() {
+ return Lifecycle.DEFAULT;
+ }
+
+ @Override
+ public Collection<Phase> phases() {
+ return asList(
+ phase("validate"),
+ phase("initialize"),
+ phase("generate-sources"),
+ phase("process-sources"),
+ phase("generate-resources"),
+ phase("process-resources"),
+ phase("compile"),
+ phase("process-classes"),
+ phase("generate-test-sources"),
+ phase("process-test-sources"),
+ phase("generate-test-resources"),
+ phase("process-test-resources"),
+ phase("test-compile"),
+ phase("process-test-classes"),
+ phase("test"),
+ phase("prepare-package"),
+ phase("package"),
+ phase("pre-integration-test"),
+ phase("integration-test"),
+ phase("post-integration-test"),
+ phase("verify"),
+ phase("install"),
+ phase("deploy"));
+ }
+ }
+
+ static class SiteLifecycle implements Lifecycle {
+
+ private static final String MAVEN_SITE_PLUGIN_VERSION = "3.12.1";
+
+ @Override
+ public String id() {
+ return Lifecycle.SITE;
+ }
+
+ @Override
+ public Collection<Phase> phases() {
+ return asList(
+ phase("pre-site"),
+ phase(
+ "site",
+ plugin(
+ "org.apache.maven.plugins:maven-site-plugin:" + MAVEN_SITE_PLUGIN_VERSION + ":site",
+ "site")),
+ phase("post-site"),
+ phase(
+ "site-deploy",
+ plugin(
+ "org.apache.maven.plugins:maven-site-plugin:" + MAVEN_SITE_PLUGIN_VERSION
+ + ":deploy",
+ "site-deploy")));
+ }
+ }
+
+ static class WrapperLifecycle implements Lifecycle {
+
+ private static final String MAVEN_WRAPPER_PLUGIN_VERSION = "3.2.0";
+
+ @Override
+ public String id() {
+ return WRAPPER;
+ }
+
+ @Override
+ public Collection<Phase> phases() {
+ return singleton(phase(
+ "wrapper",
+ plugin(
+ "org.apache.maven.plugins:maven-wrapper-plugin:" + MAVEN_WRAPPER_PLUGIN_VERSION
+ + ":wrapper",
+ "wrapper")));
+ }
+ }
+}
diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/ExtensibleEnumRegistries.java b/maven-core/src/main/java/org/apache/maven/internal/impl/ExtensibleEnumRegistries.java
index d512e74b46..e661a40397 100644
--- a/maven-core/src/main/java/org/apache/maven/internal/impl/ExtensibleEnumRegistries.java
+++ b/maven-core/src/main/java/org/apache/maven/internal/impl/ExtensibleEnumRegistries.java
@@ -25,6 +25,7 @@ import javax.inject.Singleton;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -33,6 +34,8 @@ import org.apache.maven.api.*;
import org.apache.maven.api.services.*;
import org.apache.maven.api.spi.*;
+import static org.apache.maven.internal.impl.Utils.nonNull;
+
public class ExtensibleEnumRegistries {
@Named
@@ -76,17 +79,17 @@ public class ExtensibleEnumRegistries {
static class DefaultExtensibleEnumRegistry<T extends ExtensibleEnum, P extends ExtensibleEnumProvider<T>>
implements ExtensibleEnumRegistry<T> {
- private final Map<String, T> values;
+ protected final Map<String, T> values;
DefaultExtensibleEnumRegistry(List<P> providers, T... builtinValues) {
values = Stream.<T>concat(
Stream.of(builtinValues), providers.stream().flatMap(p -> p.provides().stream()))
- .collect(Collectors.toMap(t -> t.id(), t -> t));
+ .collect(Collectors.toUnmodifiableMap(ExtensibleEnum::id, Function.identity()));
}
@Override
public Optional<T> lookup(String id) {
- return Optional.ofNullable(values.get(id));
+ return Optional.ofNullable(values.get(nonNull(id, "id")));
}
}
}
diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/Graph.java b/maven-core/src/main/java/org/apache/maven/internal/impl/Graph.java
new file mode 100644
index 0000000000..6bbdb51ab8
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/internal/impl/Graph.java
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl;
+
+import java.util.*;
+
+import org.apache.maven.project.CycleDetectedException;
+
+class Graph {
+ private enum DfsState {
+ VISITING,
+ VISITED
+ }
+
+ final Map<String, Vertex> vertices = new LinkedHashMap<>();
+
+ public Vertex getVertex(String id) {
+ return vertices.get(id);
+ }
+
+ public Collection<Vertex> getVertices() {
+ return vertices.values();
+ }
+
+ Vertex addVertex(String label) {
+ return vertices.computeIfAbsent(label, Vertex::new);
+ }
+
+ void addEdge(Vertex from, Vertex to) throws CycleDetectedException {
+ from.children.add(to);
+ to.parents.add(from);
+ List<String> cycle = findCycle(to);
+ if (cycle != null) {
+ // remove edge which introduced cycle
+ removeEdge(from, to);
+ throw new CycleDetectedException(
+ "Edge between '" + from.label + "' and '" + to.label + "' introduces to cycle in the graph", cycle);
+ }
+ }
+
+ void removeEdge(Vertex from, Vertex to) {
+ from.children.remove(to);
+ to.parents.remove(from);
+ }
+
+ List<String> visitAll() {
+ return visitAll(vertices.values(), new HashMap<>(), new ArrayList<>());
+ }
+
+ List<String> findCycle(Vertex vertex) {
+ return visitCycle(Collections.singleton(vertex), new HashMap<>(), new LinkedList<>());
+ }
+
+ private static List<String> visitAll(
+ Collection<Vertex> children, Map<Vertex, DfsState> stateMap, List<String> list) {
+ for (Vertex v : children) {
+ DfsState state = stateMap.putIfAbsent(v, DfsState.VISITING);
+ if (state == null) {
+ visitAll(v.children, stateMap, list);
+ stateMap.put(v, DfsState.VISITED);
+ list.add(v.label);
+ }
+ }
+ return list;
+ }
+
+ private static List<String> visitCycle(
+ Collection<Vertex> children, Map<Vertex, DfsState> stateMap, LinkedList<String> cycle) {
+ for (Vertex v : children) {
+ DfsState state = stateMap.putIfAbsent(v, DfsState.VISITING);
+ if (state == null) {
+ cycle.addLast(v.label);
+ List<String> ret = visitCycle(v.children, stateMap, cycle);
+ if (ret != null) {
+ return ret;
+ }
+ cycle.removeLast();
+ stateMap.put(v, DfsState.VISITED);
+ } else if (state == DfsState.VISITING) {
+ // we are already visiting this vertex, this mean we have a cycle
+ int pos = cycle.lastIndexOf(v.label);
+ List<String> ret = cycle.subList(pos, cycle.size());
+ ret.add(v.label);
+ return ret;
+ }
+ }
+ return null;
+ }
+
+ static class Vertex {
+ final String label;
+ final List<Vertex> children = new ArrayList<>();
+ final List<Vertex> parents = new ArrayList<>();
+
+ Vertex(String label) {
+ this.label = label;
+ }
+
+ String getLabel() {
+ return label;
+ }
+
+ List<Vertex> getChildren() {
+ return children;
+ }
+
+ List<Vertex> getParents() {
+ return parents;
+ }
+ }
+
+ static class CycleDetectedException extends RuntimeException {
+ private final List<String> cycle;
+
+ CycleDetectedException(String message, List<String> cycle) {
+ super(message);
+ this.cycle = cycle;
+ }
+
+ public List<String> getCycle() {
+ return cycle;
+ }
+
+ @Override
+ public String getMessage() {
+ return super.getMessage() + " " + String.join(" --> ", cycle);
+ }
+ }
+}
diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/Lifecycles.java b/maven-core/src/main/java/org/apache/maven/internal/impl/Lifecycles.java
new file mode 100644
index 0000000000..42da23b290
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/internal/impl/Lifecycles.java
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.impl;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.api.Lifecycle;
+import org.apache.maven.api.model.Plugin;
+import org.apache.maven.api.model.PluginExecution;
+
+public class Lifecycles {
+
+ static Lifecycle.Phase phase(String name) {
+ return new DefaultPhase(name, Collections.emptyList(), Collections.emptyList());
+ }
+
+ static Lifecycle.Phase phase(String name, Plugin plugin) {
+ return new DefaultPhase(name, Collections.singletonList(plugin), Collections.emptyList());
+ }
+
+ static Plugin plugin(String coord, String phase) {
+ String[] c = coord.split(":");
+ return Plugin.newBuilder()
+ .groupId(c[0])
+ .artifactId(c[1])
+ .version(c[2])
+ .executions(Collections.singletonList(PluginExecution.newBuilder()
+ .id("default-" + c[3])
+ .phase(phase)
+ .goals(Collections.singletonList(c[3]))
+ .build()))
+ .build();
+ }
+
+ static class DefaultPhase implements Lifecycle.Phase {
+ private final String name;
+ private final List<Plugin> plugins;
+ private final List<Lifecycle.Phase> phases;
+
+ DefaultPhase(String name, List<Plugin> plugins, List<Lifecycle.Phase> phases) {
+ this.name = name;
+ this.plugins = plugins;
+ this.phases = phases;
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public List<Plugin> plugins() {
+ return plugins;
+ }
+ }
+}
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java
index ed9313db75..3987985cbe 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java
@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
+import org.apache.maven.api.services.LifecycleRegistry;
import org.apache.maven.api.services.Lookup;
import org.apache.maven.api.services.LookupException;
import org.slf4j.Logger;
@@ -51,24 +52,29 @@ public class DefaultLifecycles {
private final Lookup lookup;
+ private final LifecycleRegistry registry;
+
private Map<String, Lifecycle> customLifecycles;
public DefaultLifecycles() {
this.lookup = null;
+ this.registry = null;
}
/**
- * @deprecated Rely on {@link #DefaultLifecycles(Lookup)} instead
+ * @deprecated Use {@link #DefaultLifecycles(LifecycleRegistry,Lookup)} instead
*/
@Deprecated
public DefaultLifecycles(Map<String, Lifecycle> lifecycles, org.codehaus.plexus.logging.Logger logger) {
this.customLifecycles = lifecycles;
this.lookup = null;
+ this.registry = null;
}
@Inject
- public DefaultLifecycles(Lookup lookup) {
+ public DefaultLifecycles(LifecycleRegistry registry, Lookup lookup) {
this.lookup = lookup;
+ this.registry = registry;
}
/**
@@ -149,7 +155,11 @@ public class DefaultLifecycles {
// Lifecycles cannot be cached as extensions might add custom lifecycles later in the execution.
try {
- return lookup.lookupMap(Lifecycle.class);
+ Map<String, Lifecycle> lifecycles = new HashMap<>(lookup.lookupMap(Lifecycle.class));
+ for (org.apache.maven.api.Lifecycle lf : registry) {
+ lifecycles.put(lf.id(), new Lifecycle(registry, lf));
+ }
+ return lifecycles;
} catch (LookupException e) {
throw new IllegalStateException("Unable to lookup lifecycles from the plexus container", e);
}
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java b/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java
index b3b63cbaaa..089e412ad5 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java
@@ -18,8 +18,8 @@
*/
package org.apache.maven.lifecycle;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
import org.apache.maven.lifecycle.mapping.LifecyclePhase;
@@ -35,6 +35,14 @@ public class Lifecycle {
this.defaultPhases = defaultPhases;
}
+ public Lifecycle(
+ org.apache.maven.api.services.LifecycleRegistry registry, org.apache.maven.api.Lifecycle lifecycle) {
+ this.lifecycle = lifecycle;
+ this.id = lifecycle.id();
+ this.phases = registry.computePhases(lifecycle);
+ this.defaultPhases = getDefaultPhases(lifecycle);
+ }
+
// <lifecycle>
// <id>clean</id>
// <phases>
@@ -53,12 +61,25 @@ public class Lifecycle {
private Map<String, LifecyclePhase> defaultPhases;
+ private org.apache.maven.api.Lifecycle lifecycle;
+
public String getId() {
- return this.id;
+ return id;
}
public List<String> getPhases() {
- return this.phases;
+ return phases;
+ }
+
+ static Map<String, LifecyclePhase> getDefaultPhases(org.apache.maven.api.Lifecycle lifecycle) {
+ Map<String, List<String>> goals = new HashMap<>();
+ lifecycle.phases().forEach(phase -> phase.plugins()
+ .forEach(plugin -> plugin.getExecutions().forEach(exec -> exec.getGoals()
+ .forEach(goal -> goals.computeIfAbsent(phase.name(), n -> new ArrayList<>())
+ .add(plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion()
+ + ":" + goal)))));
+ return goals.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> new LifecyclePhase(String.join(",", e.getValue()))));
}
public Map<String, LifecyclePhase> getDefaultLifecyclePhases() {
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/CleanLifecycleProvider.java b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/CleanLifecycleProvider.java
deleted file mode 100644
index cd8873d1b9..0000000000
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/CleanLifecycleProvider.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.lifecycle.providers;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-/**
- * {@code clean} lifecycle provider.
- */
-@Named(CleanLifecycleProvider.LIFECYCLE_ID)
-@Singleton
-public final class CleanLifecycleProvider extends AbstractLifecycleProvider {
- static final String LIFECYCLE_ID = "clean";
-
- // START SNIPPET: clean
- private static final String[] PHASES = {"pre-clean", "clean", "post-clean"};
-
- private static final String MAVEN_CLEAN_PLUGIN_VERSION = "3.2.0";
-
- private static final String[] BINDINGS = {
- "clean", "org.apache.maven.plugins:maven-clean-plugin:" + MAVEN_CLEAN_PLUGIN_VERSION + ":clean"
- };
- // END SNIPPET: clean
-
- @Inject
- public CleanLifecycleProvider() {
- super(LIFECYCLE_ID, PHASES, BINDINGS);
- }
-}
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/DefaultLifecycleProvider.java b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/DefaultLifecycleProvider.java
deleted file mode 100644
index 9f7602ab69..0000000000
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/DefaultLifecycleProvider.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.lifecycle.providers;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-/**
- * {@code default} lifecycle provider.
- */
-@Named(DefaultLifecycleProvider.LIFECYCLE_ID)
-@Singleton
-public final class DefaultLifecycleProvider extends AbstractLifecycleProvider {
- static final String LIFECYCLE_ID = "default";
-
- // START SNIPPET: default
- private static final String[] PHASES = {
- "validate",
- "initialize",
- "generate-sources",
- "process-sources",
- "generate-resources",
- "process-resources",
- "compile",
- "process-classes",
- "generate-test-sources",
- "process-test-sources",
- "generate-test-resources",
- "process-test-resources",
- "test-compile",
- "process-test-classes",
- "test",
- "prepare-package",
- "package",
- "pre-integration-test",
- "integration-test",
- "post-integration-test",
- "verify",
- "install",
- "deploy"
- };
- // END SNIPPET: default
-
- @Inject
- public DefaultLifecycleProvider() {
- super(
- LIFECYCLE_ID,
- PHASES,
- null // no global plugin bindings for default lifecycle: they are defined per-packaging in separate
- // providers
- );
- }
-}
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/SiteLifecycleProvider.java b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/SiteLifecycleProvider.java
deleted file mode 100644
index 8dd6439b8a..0000000000
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/SiteLifecycleProvider.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.lifecycle.providers;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-/**
- * {@code site} lifecycle provider.
- */
-@Named(SiteLifecycleProvider.LIFECYCLE_ID)
-@Singleton
-public final class SiteLifecycleProvider extends AbstractLifecycleProvider {
- static final String LIFECYCLE_ID = "site";
-
- // START SNIPPET: site
- private static final String[] PHASES = {"pre-site", "site", "post-site", "site-deploy"};
-
- private static final String MAVEN_SITE_PLUGIN_VERSION = "3.12.1";
-
- private static final String[] BINDINGS = {
- "site", "org.apache.maven.plugins:maven-site-plugin:" + MAVEN_SITE_PLUGIN_VERSION + ":site",
- "site-deploy", "org.apache.maven.plugins:maven-site-plugin:" + MAVEN_SITE_PLUGIN_VERSION + ":deploy"
- };
- // END SNIPPET: site
-
- @Inject
- public SiteLifecycleProvider() {
- super(LIFECYCLE_ID, PHASES, BINDINGS);
- }
-}
diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java
index fe42923898..99b8793eae 100644
--- a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java
+++ b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import org.apache.maven.internal.impl.DefaultLifecycleRegistry;
import org.apache.maven.internal.impl.DefaultLookup;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@@ -94,7 +95,9 @@ class DefaultLifecyclesTest {
PlexusContainer mockedPlexusContainer = mock(PlexusContainer.class);
when(mockedPlexusContainer.lookupMap(Lifecycle.class)).thenReturn(lifeCycles);
- DefaultLifecycles dl = new DefaultLifecycles(new DefaultLookup(mockedPlexusContainer));
+ DefaultLifecycles dl = new DefaultLifecycles(
+ new DefaultLifecycleRegistry(Collections.emptyList(), Collections.emptyMap()),
+ new DefaultLookup(mockedPlexusContainer));
assertThat(dl.getLifeCycles().get(0).getId(), is("clean"));
assertThat(dl.getLifeCycles().get(1).getId(), is("default"));
diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java
index 9260b8332c..65c0b65570 100644
--- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java
+++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.apache.maven.internal.impl.DefaultLifecycleRegistry;
import org.apache.maven.internal.impl.DefaultLookup;
import org.apache.maven.lifecycle.DefaultLifecycles;
import org.apache.maven.lifecycle.Lifecycle;
@@ -71,6 +72,7 @@ public class DefaultLifecyclesStub {
PlexusContainer mockedContainer = mock(PlexusContainer.class);
when(mockedContainer.lookupMap(Lifecycle.class)).thenReturn(lifeCycles);
- return new DefaultLifecycles(new DefaultLookup(mockedContainer));
+ DefaultLifecycleRegistry reg = new DefaultLifecycleRegistry();
+ return new DefaultLifecycles(reg, new DefaultLookup(mockedContainer));
}
}