mirror of https://github.com/apache/maven.git
[MNG-7974] Update Resolver 2.0.0-alpha-5 (#1337)
Update to Resolver alpha-5 and apply some cleanups. Notable changes: * update resolver to 2.0.0-alpha-5 * detach model-builder from maven-artifact (this is important) * introduce model builder own VersionParser iface (implemented in resolver-provider) * API VersionParser implementation reuses VersionParser from resolver-provider to implement the service * various other cleanups, removal of old plexus, etc --- https://issues.apache.org/jira/browse/MNG-7974
This commit is contained in:
parent
e34afc897a
commit
a1fdd89745
|
@ -18,41 +18,42 @@
|
|||
*/
|
||||
package org.apache.maven.internal.impl;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.maven.api.Version;
|
||||
import org.apache.maven.api.VersionRange;
|
||||
import org.apache.maven.api.services.VersionParser;
|
||||
import org.apache.maven.api.services.VersionParserException;
|
||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
|
||||
import static org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
|
||||
import static org.apache.maven.internal.impl.Utils.nonNull;
|
||||
|
||||
/**
|
||||
* A wrapper class around a resolver version that works as model version parser as well.
|
||||
*/
|
||||
@Named
|
||||
@Singleton
|
||||
public class DefaultVersionParser implements VersionParser {
|
||||
private static final String SNAPSHOT = "SNAPSHOT";
|
||||
private static final Pattern SNAPSHOT_TIMESTAMP = Pattern.compile("^(.*-)?([0-9]{8}\\.[0-9]{6}-[0-9]+)$");
|
||||
|
||||
private final org.apache.maven.model.version.VersionParser modelVersionParser;
|
||||
|
||||
@Inject
|
||||
public DefaultVersionParser(org.apache.maven.model.version.VersionParser modelVersionParser) {
|
||||
this.modelVersionParser = nonNull(modelVersionParser, "modelVersionParser");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version parseVersion(String version) {
|
||||
return new DefaultVersion(new DefaultArtifactVersion(nonNull(version, "version")));
|
||||
return modelVersionParser.parseVersion(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionRange parseVersionRange(String range) {
|
||||
try {
|
||||
return new DefaultVersionRange(createFromVersionSpec(nonNull(range, "version")));
|
||||
} catch (InvalidVersionSpecificationException e) {
|
||||
throw new VersionParserException("Unable to parse version range: " + range, e);
|
||||
}
|
||||
return modelVersionParser.parseVersionRange(range);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,75 +64,4 @@ public class DefaultVersionParser implements VersionParser {
|
|||
static boolean checkSnapshot(String version) {
|
||||
return version.endsWith(SNAPSHOT) || SNAPSHOT_TIMESTAMP.matcher(version).matches();
|
||||
}
|
||||
|
||||
static class DefaultVersion implements Version {
|
||||
private final ArtifactVersion delegate;
|
||||
|
||||
DefaultVersion(ArtifactVersion delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Version o) {
|
||||
if (o instanceof DefaultVersion) {
|
||||
return delegate.compareTo(((DefaultVersion) o).delegate);
|
||||
} else {
|
||||
return delegate.compareTo(new DefaultArtifactVersion(o.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@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 Objects.hash(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return delegate.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
|
||||
static class DefaultVersionRange implements VersionRange {
|
||||
private final org.apache.maven.artifact.versioning.VersionRange delegate;
|
||||
|
||||
DefaultVersionRange(org.apache.maven.artifact.versioning.VersionRange delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Version version) {
|
||||
if (version instanceof DefaultVersion) {
|
||||
return delegate.containsVersion(((DefaultVersion) version).delegate);
|
||||
} else {
|
||||
return delegate.containsVersion(new DefaultArtifactVersion(version.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return delegate.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.maven.internal.transformation.impl;
|
|||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
|
@ -62,35 +63,82 @@ import org.apache.maven.model.profile.ProfileSelector;
|
|||
import org.apache.maven.model.superpom.SuperPomProvider;
|
||||
import org.apache.maven.model.v4.MavenModelVersion;
|
||||
import org.apache.maven.model.validation.ModelValidator;
|
||||
import org.apache.maven.model.version.VersionParser;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuildingRequest;
|
||||
import org.apache.maven.project.ProjectModelResolver;
|
||||
import org.apache.maven.repository.internal.ModelCacheFactory;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.eclipse.aether.RepositorySystem;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
import org.eclipse.aether.RequestTrace;
|
||||
import org.eclipse.aether.impl.RemoteRepositoryManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Named
|
||||
class DefaultConsumerPomBuilder implements ConsumerPomBuilder {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultConsumerPomBuilder.class);
|
||||
|
||||
private static final String BOM_PACKAGING = "bom";
|
||||
|
||||
public static final String POM_PACKAGING = "pom";
|
||||
|
||||
@Inject
|
||||
PlexusContainer container;
|
||||
private ModelCacheFactory modelCacheFactory;
|
||||
|
||||
@Inject
|
||||
ModelCacheFactory modelCacheFactory;
|
||||
private ProfileInjector profileInjector;
|
||||
|
||||
public Model build(RepositorySystemSession session, MavenProject project, Path src)
|
||||
throws ModelBuildingException, ComponentLookupException {
|
||||
@Inject
|
||||
private InheritanceAssembler inheritanceAssembler;
|
||||
|
||||
@Inject
|
||||
private DependencyManagementImporter dependencyManagementImporter;
|
||||
|
||||
@Inject
|
||||
private DependencyManagementInjector dependencyManagementInjector;
|
||||
|
||||
@Inject
|
||||
private LifecycleBindingsInjector lifecycleBindingsInjector;
|
||||
|
||||
@Inject
|
||||
private ModelInterpolator modelInterpolator;
|
||||
|
||||
@Inject
|
||||
private ModelNormalizer modelNormalizer;
|
||||
|
||||
@Inject
|
||||
private ModelPathTranslator modelPathTranslator;
|
||||
|
||||
@Inject
|
||||
private ModelProcessor modelProcessor;
|
||||
|
||||
@Inject
|
||||
private ModelUrlNormalizer modelUrlNormalizer;
|
||||
|
||||
@Inject
|
||||
private ModelValidator modelValidator;
|
||||
|
||||
@Inject
|
||||
private PluginConfigurationExpander pluginConfigurationExpander;
|
||||
|
||||
@Inject
|
||||
private PluginManagementInjector pluginManagementInjector;
|
||||
|
||||
@Inject
|
||||
private ReportConfigurationExpander reportConfigurationExpander;
|
||||
|
||||
@Inject
|
||||
private SuperPomProvider superPomProvider;
|
||||
|
||||
@Inject
|
||||
private VersionParser versionParser;
|
||||
|
||||
// To break circular dependency
|
||||
@Inject
|
||||
private Provider<RepositorySystem> repositorySystem;
|
||||
|
||||
@Inject
|
||||
private RemoteRepositoryManager remoteRepositoryManager;
|
||||
|
||||
@Override
|
||||
public Model build(RepositorySystemSession session, MavenProject project, Path src) throws ModelBuildingException {
|
||||
Model model = project.getModel().getDelegate();
|
||||
String packaging = model.getPackaging();
|
||||
String originalPackaging = project.getOriginalModel().getPackaging();
|
||||
|
@ -102,21 +150,21 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder {
|
|||
}
|
||||
|
||||
protected Model buildPom(RepositorySystemSession session, MavenProject project, Path src)
|
||||
throws ModelBuildingException, ComponentLookupException {
|
||||
throws ModelBuildingException {
|
||||
ModelBuildingResult result = buildModel(session, project, src);
|
||||
Model model = result.getRawModel().getDelegate();
|
||||
return transform(model, project);
|
||||
}
|
||||
|
||||
protected Model buildNonPom(RepositorySystemSession session, MavenProject project, Path src)
|
||||
throws ModelBuildingException, ComponentLookupException {
|
||||
throws ModelBuildingException {
|
||||
ModelBuildingResult result = buildModel(session, project, src);
|
||||
Model model = result.getEffectiveModel().getDelegate();
|
||||
return transform(model, project);
|
||||
}
|
||||
|
||||
private ModelBuildingResult buildModel(RepositorySystemSession session, MavenProject project, Path src)
|
||||
throws ModelBuildingException, ComponentLookupException {
|
||||
throws ModelBuildingException {
|
||||
ProfileSelector customSelector = new DefaultProfileSelector() {
|
||||
@Override
|
||||
public List<Profile> getActiveProfilesV4(
|
||||
|
@ -127,21 +175,22 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder {
|
|||
DefaultModelBuilder modelBuilder = new DefaultModelBuilderFactory()
|
||||
.setProfileSelector(customSelector)
|
||||
// apply currently active ModelProcessor etc. to support extensions like jgitver
|
||||
.setProfileInjector(lookup(ProfileInjector.class))
|
||||
.setInheritanceAssembler(lookup(InheritanceAssembler.class))
|
||||
.setDependencyManagementImporter(lookup(DependencyManagementImporter.class))
|
||||
.setDependencyManagementInjector(lookup(DependencyManagementInjector.class))
|
||||
.setLifecycleBindingsInjector(lookup(LifecycleBindingsInjector.class))
|
||||
.setModelInterpolator(lookup(ModelInterpolator.class))
|
||||
.setModelNormalizer(lookup(ModelNormalizer.class))
|
||||
.setModelPathTranslator(lookup(ModelPathTranslator.class))
|
||||
.setModelProcessor(lookup(ModelProcessor.class))
|
||||
.setModelUrlNormalizer(lookup(ModelUrlNormalizer.class))
|
||||
.setModelValidator(lookup(ModelValidator.class))
|
||||
.setPluginConfigurationExpander(lookup(PluginConfigurationExpander.class))
|
||||
.setPluginManagementInjector(lookup(PluginManagementInjector.class))
|
||||
.setReportConfigurationExpander(lookup(ReportConfigurationExpander.class))
|
||||
.setSuperPomProvider(lookup(SuperPomProvider.class))
|
||||
.setProfileInjector(profileInjector)
|
||||
.setInheritanceAssembler(inheritanceAssembler)
|
||||
.setDependencyManagementImporter(dependencyManagementImporter)
|
||||
.setDependencyManagementInjector(dependencyManagementInjector)
|
||||
.setLifecycleBindingsInjector(lifecycleBindingsInjector)
|
||||
.setModelInterpolator(modelInterpolator)
|
||||
.setModelNormalizer(modelNormalizer)
|
||||
.setModelPathTranslator(modelPathTranslator)
|
||||
.setModelProcessor(modelProcessor)
|
||||
.setModelUrlNormalizer(modelUrlNormalizer)
|
||||
.setModelValidator(modelValidator)
|
||||
.setPluginConfigurationExpander(pluginConfigurationExpander)
|
||||
.setPluginManagementInjector(pluginManagementInjector)
|
||||
.setReportConfigurationExpander(reportConfigurationExpander)
|
||||
.setSuperPomProvider(superPomProvider)
|
||||
.setModelVersionParser(versionParser)
|
||||
.newInstance();
|
||||
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
|
||||
try {
|
||||
|
@ -155,8 +204,8 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder {
|
|||
request.setModelResolver(new ProjectModelResolver(
|
||||
session,
|
||||
new RequestTrace(null),
|
||||
lookup(RepositorySystem.class),
|
||||
lookup(RemoteRepositoryManager.class),
|
||||
repositorySystem.get(),
|
||||
remoteRepositoryManager,
|
||||
project.getRemoteProjectRepositories(),
|
||||
ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT,
|
||||
null));
|
||||
|
@ -173,10 +222,6 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder {
|
|||
return props;
|
||||
}
|
||||
|
||||
private <T> T lookup(Class<T> clazz) throws ComponentLookupException {
|
||||
return container.lookup(clazz);
|
||||
}
|
||||
|
||||
static Model transform(Model model, MavenProject project) {
|
||||
String packaging = model.getPackaging();
|
||||
if (POM_PACKAGING.equals(packaging)) {
|
||||
|
|
|
@ -83,7 +83,6 @@ import org.apache.maven.plugin.version.PluginVersionResolver;
|
|||
import org.apache.maven.project.ExtensionDescriptor;
|
||||
import org.apache.maven.project.ExtensionDescriptorBuilder;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.rtinfo.RuntimeInformation;
|
||||
import org.apache.maven.session.scope.internal.SessionScopeModule;
|
||||
import org.codehaus.plexus.DefaultPlexusContainer;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
|
@ -134,19 +133,18 @@ public class DefaultMavenPluginManager implements MavenPluginManager {
|
|||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private PlexusContainer container;
|
||||
private ClassRealmManager classRealmManager;
|
||||
private PluginDescriptorCache pluginDescriptorCache;
|
||||
private PluginRealmCache pluginRealmCache;
|
||||
private DefaultPluginDependenciesResolver pluginDependenciesResolver;
|
||||
private RuntimeInformation runtimeInformation;
|
||||
private ExtensionRealmCache extensionRealmCache;
|
||||
private PluginVersionResolver pluginVersionResolver;
|
||||
private PluginArtifactsCache pluginArtifactsCache;
|
||||
private MavenPluginValidator pluginValidator;
|
||||
private List<MavenPluginConfigurationValidator> configurationValidators;
|
||||
private PluginValidationManager pluginValidationManager;
|
||||
private List<MavenPluginPrerequisitesChecker> prerequisitesCheckers;
|
||||
private final PlexusContainer container;
|
||||
private final ClassRealmManager classRealmManager;
|
||||
private final PluginDescriptorCache pluginDescriptorCache;
|
||||
private final PluginRealmCache pluginRealmCache;
|
||||
private final DefaultPluginDependenciesResolver pluginDependenciesResolver;
|
||||
private final ExtensionRealmCache extensionRealmCache;
|
||||
private final PluginVersionResolver pluginVersionResolver;
|
||||
private final PluginArtifactsCache pluginArtifactsCache;
|
||||
private final MavenPluginValidator pluginValidator;
|
||||
private final List<MavenPluginConfigurationValidator> configurationValidators;
|
||||
private final PluginValidationManager pluginValidationManager;
|
||||
private final List<MavenPluginPrerequisitesChecker> prerequisitesCheckers;
|
||||
private final ExtensionDescriptorBuilder extensionDescriptorBuilder = new ExtensionDescriptorBuilder();
|
||||
private final PluginDescriptorBuilder builder = new PluginDescriptorBuilder();
|
||||
|
||||
|
@ -158,7 +156,6 @@ public class DefaultMavenPluginManager implements MavenPluginManager {
|
|||
PluginDescriptorCache pluginDescriptorCache,
|
||||
PluginRealmCache pluginRealmCache,
|
||||
DefaultPluginDependenciesResolver pluginDependenciesResolver,
|
||||
RuntimeInformation runtimeInformation,
|
||||
ExtensionRealmCache extensionRealmCache,
|
||||
PluginVersionResolver pluginVersionResolver,
|
||||
PluginArtifactsCache pluginArtifactsCache,
|
||||
|
@ -171,7 +168,6 @@ public class DefaultMavenPluginManager implements MavenPluginManager {
|
|||
this.pluginDescriptorCache = pluginDescriptorCache;
|
||||
this.pluginRealmCache = pluginRealmCache;
|
||||
this.pluginDependenciesResolver = pluginDependenciesResolver;
|
||||
this.runtimeInformation = runtimeInformation;
|
||||
this.extensionRealmCache = extensionRealmCache;
|
||||
this.pluginVersionResolver = pluginVersionResolver;
|
||||
this.pluginArtifactsCache = pluginArtifactsCache;
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.codehaus.plexus.configuration.PlexusConfiguration;
|
|||
* Service responsible for validating plugin configuration.
|
||||
*
|
||||
*/
|
||||
interface MavenPluginConfigurationValidator {
|
||||
public interface MavenPluginConfigurationValidator {
|
||||
/**
|
||||
* Checks mojo configuration issues.
|
||||
*/
|
||||
|
|
|
@ -32,11 +32,10 @@ import org.eclipse.aether.version.VersionScheme;
|
|||
@Named
|
||||
@Singleton
|
||||
public class MavenPluginJavaPrerequisiteChecker implements MavenPluginPrerequisitesChecker {
|
||||
|
||||
private final VersionScheme versionScheme;
|
||||
|
||||
@Inject
|
||||
public MavenPluginJavaPrerequisiteChecker(final VersionScheme versionScheme) {
|
||||
public MavenPluginJavaPrerequisiteChecker(VersionScheme versionScheme) {
|
||||
this.versionScheme = versionScheme;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
|||
/**
|
||||
* MavenPluginValidator
|
||||
*/
|
||||
interface MavenPluginValidator {
|
||||
public interface MavenPluginValidator {
|
||||
|
||||
void validate(Artifact pluginArtifact, PluginDescriptor pluginDescriptor, List<String> errors);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class DefaultRuntimeInformation implements RuntimeInformation {
|
|||
private final String mavenVersion;
|
||||
|
||||
@Inject
|
||||
public DefaultRuntimeInformation(final VersionScheme versionScheme) {
|
||||
public DefaultRuntimeInformation(VersionScheme versionScheme) {
|
||||
this.versionScheme = versionScheme;
|
||||
this.mavenVersion = loadMavenVersion();
|
||||
}
|
||||
|
|
|
@ -48,10 +48,6 @@ under the License.
|
|||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-model</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-artifact</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-builder-support</artifactId>
|
||||
|
|
|
@ -32,12 +32,11 @@ import java.util.function.Function;
|
|||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.maven.api.VersionRange;
|
||||
import org.apache.maven.api.feature.Features;
|
||||
import org.apache.maven.api.model.Exclusion;
|
||||
import org.apache.maven.api.model.InputSource;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
import org.apache.maven.api.services.VersionParserException;
|
||||
import org.apache.maven.building.Source;
|
||||
import org.apache.maven.model.Activation;
|
||||
import org.apache.maven.model.Build;
|
||||
|
@ -50,7 +49,6 @@ import org.apache.maven.model.Plugin;
|
|||
import org.apache.maven.model.PluginManagement;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.building.ModelProblem.Severity;
|
||||
import org.apache.maven.model.building.ModelProblem.Version;
|
||||
import org.apache.maven.model.composition.DependencyManagementImporter;
|
||||
import org.apache.maven.model.inheritance.InheritanceAssembler;
|
||||
import org.apache.maven.model.interpolation.ModelInterpolator;
|
||||
|
@ -78,6 +76,7 @@ import org.apache.maven.model.resolution.WorkspaceModelResolver;
|
|||
import org.apache.maven.model.superpom.SuperPomProvider;
|
||||
import org.apache.maven.model.validation.DefaultModelValidator;
|
||||
import org.apache.maven.model.validation.ModelValidator;
|
||||
import org.apache.maven.model.version.VersionParser;
|
||||
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||
import org.codehaus.plexus.interpolation.MapBasedValueSource;
|
||||
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
|
||||
|
@ -111,6 +110,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
private final ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator;
|
||||
private final ModelVersionProcessor versionProcessor;
|
||||
private final ModelSourceTransformer transformer;
|
||||
private final VersionParser versionParser;
|
||||
|
||||
@SuppressWarnings("checkstyle:ParameterNumber")
|
||||
@Inject
|
||||
|
@ -133,7 +133,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
ReportConfigurationExpander reportConfigurationExpander,
|
||||
ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator,
|
||||
ModelVersionProcessor versionProcessor,
|
||||
ModelSourceTransformer transformer) {
|
||||
ModelSourceTransformer transformer,
|
||||
VersionParser versionParser) {
|
||||
this.modelProcessor = modelProcessor;
|
||||
this.modelValidator = modelValidator;
|
||||
this.modelNormalizer = modelNormalizer;
|
||||
|
@ -153,6 +154,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
this.profileActivationFilePathInterpolator = profileActivationFilePathInterpolator;
|
||||
this.versionProcessor = versionProcessor;
|
||||
this.transformer = transformer;
|
||||
this.versionParser = versionParser;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,7 +182,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -208,7 +211,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,7 +240,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -264,7 +269,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -292,7 +298,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -320,7 +327,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -348,7 +356,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -376,7 +385,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -404,7 +414,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -432,7 +443,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -460,7 +472,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -489,7 +502,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -518,7 +532,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -546,7 +561,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -574,7 +590,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -602,7 +619,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -631,7 +649,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
reportConfigurationExpander,
|
||||
profileActivationFilePathInterpolator,
|
||||
versionProcessor,
|
||||
transformer);
|
||||
transformer,
|
||||
versionParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -921,7 +940,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
String path,
|
||||
InterpolationException e,
|
||||
String locationKey) {
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
|
||||
.setMessage("Failed to interpolate file location " + path + ": " + e.getMessage())
|
||||
.setLocation(Optional.ofNullable(file.getLocation(locationKey))
|
||||
.map(InputLocation::new)
|
||||
|
@ -1036,7 +1055,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
transformer.transform(pomFile.toPath(), context, model);
|
||||
}
|
||||
} catch (TransformerException e) {
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.V40).setException(e));
|
||||
problems.add(
|
||||
new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V40).setException(e));
|
||||
}
|
||||
|
||||
return newResult(model, problems.getProblems());
|
||||
|
@ -1108,7 +1128,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
}
|
||||
|
||||
Severity severity = (modelSource instanceof FileModelSource) ? Severity.ERROR : Severity.WARNING;
|
||||
problems.add(new ModelProblemCollectorRequest(severity, Version.V20)
|
||||
problems.add(new ModelProblemCollectorRequest(severity, ModelProblem.Version.V20)
|
||||
.setMessage("Malformed POM " + modelSource.getLocation() + ": " + e.getMessage())
|
||||
.setException(e));
|
||||
}
|
||||
|
@ -1128,7 +1148,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
}
|
||||
}
|
||||
} catch (ModelParseException e) {
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.BASE)
|
||||
.setMessage("Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage())
|
||||
.setException(e));
|
||||
throw problems.newModelBuildingException();
|
||||
|
@ -1142,7 +1162,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
msg = e.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.BASE)
|
||||
.setMessage("Non-readable POM " + modelSource.getLocation() + ": " + msg)
|
||||
.setException(e));
|
||||
throw problems.newModelBuildingException();
|
||||
|
@ -1193,7 +1213,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
transformer.transform(pomFile.toPath(), context, rawModel);
|
||||
}
|
||||
} catch (TransformerException e) {
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.V40).setException(e));
|
||||
problems.add(
|
||||
new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V40).setException(e));
|
||||
}
|
||||
} else if (request.getFileModel() == null) {
|
||||
rawModel = readFileModel(request, problems);
|
||||
|
@ -1264,7 +1285,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
try {
|
||||
modelResolver.addRepository(repository, replaceRepositories);
|
||||
} catch (InvalidRepositoryException e) {
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
|
||||
.setMessage("Invalid repository " + repository.getId() + ": " + e.getMessage())
|
||||
.setLocation(new InputLocation(repository.getLocation("")))
|
||||
.setException(e));
|
||||
|
@ -1307,7 +1328,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
for (String key : versions.keySet()) {
|
||||
if (versions.get(key) == null && managedVersions.get(key) == null) {
|
||||
InputLocation location = plugins.get(key).getLocation("");
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.WARNING, Version.V20)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.WARNING, ModelProblem.Version.V20)
|
||||
.setMessage("'build.plugins.plugin.version' for " + key + " is missing.")
|
||||
.setLocation(location));
|
||||
}
|
||||
|
@ -1376,7 +1397,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
ssi.interpolate(interpolatedModel.getParent().getVersion());
|
||||
interpolatedModel.getParent().setVersion(interpolated);
|
||||
} catch (Exception e) {
|
||||
ModelProblemCollectorRequest mpcr = new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
|
||||
ModelProblemCollectorRequest mpcr = new ModelProblemCollectorRequest(
|
||||
Severity.ERROR, ModelProblem.Version.BASE)
|
||||
.setMessage("Failed to interpolate field: "
|
||||
+ interpolatedModel.getParent().getVersion()
|
||||
+ " on class: ")
|
||||
|
@ -1406,7 +1428,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
|
||||
Model parentModel = parentData.getModel();
|
||||
if (!"pom".equals(parentModel.getPackaging())) {
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
|
||||
.setMessage("Invalid packaging for parent POM " + ModelProblemUtils.toSourceHint(parentModel)
|
||||
+ ", must be \"pom\" but is \"" + parentModel.getPackaging() + "\"")
|
||||
.setLocation(parentModel.getLocation("packaging")));
|
||||
|
@ -1439,7 +1461,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
candidateModel =
|
||||
resolver.resolveRawModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
|
||||
} catch (UnresolvableModelException e) {
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE) //
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.BASE) //
|
||||
.setMessage(e.getMessage())
|
||||
.setLocation(parent.getLocation(""))
|
||||
.setException(e));
|
||||
|
@ -1474,7 +1496,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
buffer.append(parent.getArtifactId()).append(", please verify your project structure");
|
||||
|
||||
problems.setSource(childModel);
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.WARNING, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.WARNING, ModelProblem.Version.BASE)
|
||||
.setMessage(buffer.toString())
|
||||
.setLocation(parent.getLocation("")));
|
||||
return null;
|
||||
|
@ -1483,12 +1505,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
String version = getVersion(candidateModel);
|
||||
if (version != null && parent.getVersion() != null && !version.equals(parent.getVersion())) {
|
||||
try {
|
||||
VersionRange parentRange = VersionRange.createFromVersionSpec(parent.getVersion());
|
||||
if (!parentRange.hasRestrictions()) {
|
||||
// the parent version is not a range, we have version skew, drop back to resolution from repo
|
||||
return null;
|
||||
}
|
||||
if (!parentRange.containsVersion(new DefaultArtifactVersion(version))) {
|
||||
VersionRange parentRange = versionParser.parseVersionRange(parent.getVersion());
|
||||
if (!parentRange.contains(versionParser.parseVersion(version))) {
|
||||
// version skew drop back to resolution from the repository
|
||||
return null;
|
||||
}
|
||||
|
@ -1498,21 +1516,21 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
|
||||
if (rawChildModelVersion == null) {
|
||||
// Message below is checked for in the MNG-2199 core IT.
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.V31)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V31)
|
||||
.setMessage("Version must be a constant")
|
||||
.setLocation(childModel.getLocation("")));
|
||||
|
||||
} else {
|
||||
if (rawChildVersionReferencesParent(rawChildModelVersion)) {
|
||||
// Message below is checked for in the MNG-2199 core IT.
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.V31)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V31)
|
||||
.setMessage("Version must be a constant")
|
||||
.setLocation(childModel.getLocation("version")));
|
||||
}
|
||||
}
|
||||
|
||||
// MNG-2199: What else to check here ?
|
||||
} catch (InvalidVersionSpecificationException e) {
|
||||
} catch (VersionParserException e) {
|
||||
// invalid version range, so drop back to resolution from the repository
|
||||
return null;
|
||||
}
|
||||
|
@ -1596,7 +1614,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.BASE)
|
||||
.setMessage(buffer.toString())
|
||||
.setLocation(parent.getLocation(""))
|
||||
.setException(e));
|
||||
|
@ -1616,14 +1634,14 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
|
||||
if (rawChildModelVersion == null) {
|
||||
// Message below is checked for in the MNG-2199 core IT.
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.V31)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V31)
|
||||
.setMessage("Version must be a constant")
|
||||
.setLocation(childModel.getLocation("")));
|
||||
|
||||
} else {
|
||||
if (rawChildVersionReferencesParent(rawChildModelVersion)) {
|
||||
// Message below is checked for in the MNG-2199 core IT.
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.V31)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V31)
|
||||
.setMessage("Version must be a constant")
|
||||
.setLocation(childModel.getLocation("version")));
|
||||
}
|
||||
|
@ -1695,21 +1713,21 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
String version = dependency.getVersion();
|
||||
|
||||
if (groupId == null || groupId.length() <= 0) {
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
|
||||
.setMessage("'dependencyManagement.dependencies.dependency.groupId' for "
|
||||
+ dependency.getManagementKey() + " is missing.")
|
||||
.setLocation(dependency.getLocation("")));
|
||||
return null;
|
||||
}
|
||||
if (artifactId == null || artifactId.length() <= 0) {
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
|
||||
.setMessage("'dependencyManagement.dependencies.dependency.artifactId' for "
|
||||
+ dependency.getManagementKey() + " is missing.")
|
||||
.setLocation(dependency.getLocation("")));
|
||||
return null;
|
||||
}
|
||||
if (version == null || version.length() <= 0) {
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
|
||||
.setMessage("'dependencyManagement.dependencies.dependency.version' for "
|
||||
+ dependency.getManagementKey() + " is missing.")
|
||||
.setLocation(dependency.getLocation("")));
|
||||
|
@ -1725,7 +1743,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
message.append(modelId).append(" -> ");
|
||||
}
|
||||
message.append(imported);
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE).setMessage(message.toString()));
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
|
||||
.setMessage(message.toString()));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -1786,7 +1805,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
try {
|
||||
importModel = workspaceResolver.resolveEffectiveModel(groupId, artifactId, version);
|
||||
} catch (UnresolvableModelException e) {
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.BASE)
|
||||
.setMessage(e.getMessage())
|
||||
.setException(e));
|
||||
return null;
|
||||
|
@ -1806,7 +1825,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
}
|
||||
buffer.append(": ").append(e.getMessage());
|
||||
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
|
||||
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
|
||||
.setMessage(buffer.toString())
|
||||
.setLocation(dependency.getLocation(""))
|
||||
.setException(e));
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.apache.maven.model.building;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.maven.api.Version;
|
||||
import org.apache.maven.api.VersionRange;
|
||||
import org.apache.maven.api.spi.ModelParser;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.composition.DefaultDependencyManagementImporter;
|
||||
|
@ -71,6 +73,9 @@ import org.apache.maven.model.superpom.DefaultSuperPomProvider;
|
|||
import org.apache.maven.model.superpom.SuperPomProvider;
|
||||
import org.apache.maven.model.validation.DefaultModelValidator;
|
||||
import org.apache.maven.model.validation.ModelValidator;
|
||||
import org.apache.maven.model.version.VersionParser;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* A factory to create model builder instances when no dependency injection is available. <em>Note:</em> This class is
|
||||
|
@ -101,8 +106,7 @@ public class DefaultModelBuilderFactory {
|
|||
private ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator;
|
||||
private ModelVersionProcessor versionProcessor;
|
||||
private ModelSourceTransformer transformer;
|
||||
|
||||
private RootLocator rootLocator;
|
||||
private VersionParser versionParser;
|
||||
|
||||
public DefaultModelBuilderFactory setModelProcessor(ModelProcessor modelProcessor) {
|
||||
this.modelProcessor = modelProcessor;
|
||||
|
@ -205,13 +209,13 @@ public class DefaultModelBuilderFactory {
|
|||
return this;
|
||||
}
|
||||
|
||||
public DefaultModelBuilderFactory setRootLocator(RootLocator rootLocator) {
|
||||
this.rootLocator = rootLocator;
|
||||
public DefaultModelBuilderFactory setTransformer(ModelSourceTransformer transformer) {
|
||||
this.transformer = transformer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultModelBuilderFactory setTransformer(ModelSourceTransformer transformer) {
|
||||
this.transformer = transformer;
|
||||
public DefaultModelBuilderFactory setModelVersionParser(VersionParser versionParser) {
|
||||
this.versionParser = versionParser;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -333,6 +337,33 @@ public class DefaultModelBuilderFactory {
|
|||
return new BuildModelSourceTransformer();
|
||||
}
|
||||
|
||||
private VersionParser newModelVersionParser() {
|
||||
// This is a limited parser that does not support ranges and compares versions as strings
|
||||
// in real-life this parser should not be used, but replaced with a proper one
|
||||
return new VersionParser() {
|
||||
@Override
|
||||
public Version parseVersion(String version) {
|
||||
requireNonNull(version, "version");
|
||||
return new Version() {
|
||||
@Override
|
||||
public String asString() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Version o) {
|
||||
return version.compareTo(o.asString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionRange parseVersionRange(String range) {
|
||||
throw new IllegalArgumentException("ranges not supported by this parser");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new model builder instance.
|
||||
*
|
||||
|
@ -360,7 +391,8 @@ public class DefaultModelBuilderFactory {
|
|||
? profileActivationFilePathInterpolator
|
||||
: newProfileActivationFilePathInterpolator(),
|
||||
versionProcessor != null ? versionProcessor : newModelVersionPropertiesProcessor(),
|
||||
transformer != null ? transformer : newModelSourceTransformer());
|
||||
transformer != null ? transformer : newModelSourceTransformer(),
|
||||
versionParser != null ? versionParser : newModelVersionParser());
|
||||
}
|
||||
|
||||
private static class StubLifecycleBindingsInjector implements LifecycleBindingsInjector {
|
||||
|
|
|
@ -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.model.version;
|
||||
|
||||
import org.apache.maven.api.Version;
|
||||
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 VersionParser {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* 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.repository.internal;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.maven.api.Version;
|
||||
import org.apache.maven.api.VersionRange;
|
||||
import org.apache.maven.api.services.VersionParserException;
|
||||
import org.apache.maven.model.version.VersionParser;
|
||||
import org.eclipse.aether.version.InvalidVersionSpecificationException;
|
||||
import org.eclipse.aether.version.VersionScheme;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@Named
|
||||
@Singleton
|
||||
public class DefaultModelVersionParser implements VersionParser {
|
||||
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);
|
||||
}
|
||||
|
||||
static class DefaultVersion implements Version {
|
||||
private final VersionScheme versionScheme;
|
||||
private final org.eclipse.aether.version.Version 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 Objects.hash(delegate);
|
||||
}
|
||||
|
||||
@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, 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 String asString() {
|
||||
return delegate.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
}
|
2
pom.xml
2
pom.xml
|
@ -176,7 +176,7 @@ under the License.
|
|||
<plexusInterpolationVersion>1.26</plexusInterpolationVersion>
|
||||
<plexusTestingVersion>1.0.0</plexusTestingVersion>
|
||||
<plexusXmlVersion>4.0.1</plexusXmlVersion>
|
||||
<resolverVersion>2.0.0-alpha-3</resolverVersion>
|
||||
<resolverVersion>2.0.0-alpha-5</resolverVersion>
|
||||
<securityDispatcherVersion>2.0</securityDispatcherVersion>
|
||||
<sisuVersion>0.9.0.M2</sisuVersion>
|
||||
<slf4jVersion>1.7.36</slf4jVersion>
|
||||
|
|
Loading…
Reference in New Issue