Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.codehaus.mojo.versions.ordering.BoundArtifactVersion;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.ordering.VersionComparator;
import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache;
import org.codehaus.mojo.versions.utils.ArtifactVersionService;

import static java.util.Collections.reverseOrder;
import static java.util.Optional.empty;
Expand All @@ -63,8 +63,14 @@ public abstract class AbstractVersionDetails implements VersionDetails {
*/
private ArtifactVersion currentVersion = null;

/**
* holds the current version range
*/
private VersionRange currentVersionRange = null;

/**
* displays more verbose information about discovered updates
*/
protected boolean verboseDetail = true;

protected AbstractVersionDetails() {}
Expand Down Expand Up @@ -128,7 +134,7 @@ public Restriction restrictionForUnchangedSegment(
selectedRestriction.map(Restriction::getUpperBound).orElse(actualVersion);
ArtifactVersion lowerBound = allowDowngrade
? getLowerBound(selectedRestrictionUpperBound, unchangedSegment)
.map(DefaultArtifactVersionCache::of)
.map(ArtifactVersionService::getArtifactVersion)
.orElse(null)
: selectedRestrictionUpperBound;
ArtifactVersion upperBound = unchangedSegment
Expand Down Expand Up @@ -176,7 +182,7 @@ public final void setCurrentVersionRange(VersionRange versionRange) {

@Override
public final void setCurrentVersion(String currentVersion) {
setCurrentVersion(currentVersion == null ? null : DefaultArtifactVersionCache.of(currentVersion));
setCurrentVersion(currentVersion == null ? null : ArtifactVersionService.getArtifactVersion(currentVersion));
}

@Override
Expand Down Expand Up @@ -230,10 +236,10 @@ public final boolean containsVersion(String version) {
public final ArtifactVersion[] getNewerVersions(
String versionString, Optional<Segment> unchangedSegment, boolean includeSnapshots, boolean allowDowngrade)
throws InvalidSegmentException {
ArtifactVersion currentVersion = DefaultArtifactVersionCache.of(versionString);
ArtifactVersion currentVersion = ArtifactVersionService.getArtifactVersion(versionString);
ArtifactVersion lowerBound = allowDowngrade
? getLowerBound(currentVersion, unchangedSegment)
.map(DefaultArtifactVersionCache::of)
.map(ArtifactVersionService::getArtifactVersion)
.orElse(null)
: currentVersion;
ArtifactVersion upperBound = unchangedSegment
Expand All @@ -250,7 +256,7 @@ public Optional<ArtifactVersion> getNewestVersion(
String actualVersion, Optional<Segment> unchangedSegment, boolean includeSnapshots, boolean allowDowngrade)
throws InvalidSegmentException {
Restriction segmentRestriction = restrictionForUnchangedSegment(
DefaultArtifactVersionCache.of(actualVersion), unchangedSegment, allowDowngrade);
ArtifactVersionService.getArtifactVersion(actualVersion), unchangedSegment, allowDowngrade);
Restriction lookupRestriction;
if (!allowDowngrade
&& Optional.ofNullable(currentVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
* @since 1.0-alpha-3
*/
public interface ArtifactAssociation extends Comparable<ArtifactAssociation> {
/**
* @return whether the current association uses plugin repositories
*/
boolean isUsePluginRepositories();

/**
* @return associated artifact
*/
Artifact getArtifact();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import javax.xml.stream.XMLStreamException;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
Expand All @@ -34,7 +33,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
Expand All @@ -57,10 +55,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.Restriction;
import org.apache.maven.artifact.versioning.VersionRange;
Expand All @@ -81,7 +76,8 @@
import org.codehaus.mojo.versions.model.io.stax.RuleStaxReader;
import org.codehaus.mojo.versions.ordering.VersionComparator;
import org.codehaus.mojo.versions.ordering.VersionComparators;
import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache;
import org.codehaus.mojo.versions.utils.ArtifactFactory;
import org.codehaus.mojo.versions.utils.ArtifactVersionService;
import org.codehaus.mojo.versions.utils.DependencyComparator;
import org.codehaus.mojo.versions.utils.PluginComparator;
import org.codehaus.mojo.versions.utils.RegexUtils;
Expand All @@ -99,6 +95,7 @@

import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
Expand Down Expand Up @@ -128,7 +125,7 @@ RuleSet getRuleSet() {
*/
private RuleSet ruleSet;

private final ArtifactHandlerManager artifactHandlerManager;
private final ArtifactFactory artifactFactory;

private final RepositorySystem repositorySystem;

Expand Down Expand Up @@ -166,12 +163,12 @@ RuleSet getRuleSet() {
* Private constructor used by the builder
*/
private DefaultVersionsHelper(
ArtifactHandlerManager artifactHandlerManager,
ArtifactFactory artifactFactory,
RepositorySystem repositorySystem,
MavenSession mavenSession,
MojoExecution mojoExecution,
Log log) {
this.artifactHandlerManager = artifactHandlerManager;
this.artifactFactory = requireNonNull(artifactFactory);
this.repositorySystem = repositorySystem;
this.mavenSession = mavenSession;
this.mojoExecution = mojoExecution;
Expand Down Expand Up @@ -310,7 +307,7 @@ public ArtifactVersions lookupArtifactVersions(

return false;
}))
.map(v -> DefaultArtifactVersionCache.of(v.toString()))
.map(v -> ArtifactVersionService.getArtifactVersion(v.toString()))
.collect(Collectors.toList()),
getVersionComparator(artifact));
} catch (VersionRangeResolutionException e) {
Expand Down Expand Up @@ -451,68 +448,6 @@ protected Rule getBestFitRule(String groupId, String artifactId) {
return bestFit;
}

@Override
public Artifact createPluginArtifact(String groupId, String artifactId, String version) {
return createDependencyArtifact(groupId, artifactId, version, "maven-plugin", null, "runtime", false);
}

@Override
public Artifact createDependencyArtifact(
String groupId,
String artifactId,
String version,
String type,
String classifier,
String scope,
boolean optional) {
try {
return new DefaultArtifact(
groupId,
artifactId,
VersionRange.createFromVersionSpec(StringUtils.isNotBlank(version) ? version : "[0,]"),
scope,
type,
classifier,
artifactHandlerManager.getArtifactHandler(type),
optional);
} catch (InvalidVersionSpecificationException e) {
// version should have a proper format
throw new RuntimeException(e);
}
}

@Override
public Artifact createDependencyArtifact(Dependency dependency) {
Artifact artifact = createDependencyArtifact(
dependency.getGroupId(),
dependency.getArtifactId(),
dependency.getVersion(),
dependency.getType(),
dependency.getClassifier(),
dependency.getScope(),
false);

if (Artifact.SCOPE_SYSTEM.equals(dependency.getScope()) && dependency.getSystemPath() != null) {
artifact.setFile(new File(dependency.getSystemPath()));
}
return artifact;
}

@Override
public Set<Artifact> extractArtifacts(Collection<MavenProject> mavenProjects) {
Set<Artifact> result = new HashSet<>();
for (MavenProject project : mavenProjects) {
result.add(project.getArtifact());
}

return result;
}

@Override
public ArtifactVersion createArtifactVersion(String version) {
return DefaultArtifactVersionCache.of(version);
}

public Map<Dependency, ArtifactVersions> lookupDependenciesUpdates(
Stream<Dependency> dependencies,
boolean usePluginRepositories,
Expand Down Expand Up @@ -557,7 +492,7 @@ public ArtifactVersions lookupDependencyUpdates(
boolean allowSnapshots)
throws VersionRetrievalException {
ArtifactVersions allVersions = lookupArtifactVersions(
createDependencyArtifact(dependency), null, usePluginRepositories, useProjectRepositories);
artifactFactory.createArtifact(dependency), null, usePluginRepositories, useProjectRepositories);
return new ArtifactVersions(
allVersions.getArtifact(),
Arrays.stream(allVersions.getAllUpdates(allowSnapshots)).collect(Collectors.toList()),
Expand Down Expand Up @@ -600,7 +535,7 @@ public PluginUpdatesDetails lookupPluginUpdates(Plugin plugin, boolean allowSnap
lookupDependenciesUpdates(pluginDependencies.stream(), false, allowSnapshots);

ArtifactVersions allVersions = lookupArtifactVersions(
createPluginArtifact(plugin.getGroupId(), plugin.getArtifactId(), version), true);
artifactFactory.createMavenPluginArtifact(plugin.getGroupId(), plugin.getArtifactId(), version), true);
ArtifactVersions updatedVersions = new ArtifactVersions(
allVersions.getArtifact(),
Arrays.stream(allVersions.getAllUpdates(allowSnapshots)).collect(Collectors.toList()),
Expand All @@ -617,15 +552,19 @@ public ExpressionEvaluator getExpressionEvaluator(MavenProject project) {
public Map<Property, PropertyVersions> getVersionPropertiesMap(VersionPropertiesMapRequest request)
throws MojoExecutionException {
Map<String, Property> properties = new HashMap<>();
// Populate properties map from request
if (request.getPropertyDefinitions() != null) {
Arrays.stream(request.getPropertyDefinitions()).forEach(p -> properties.put(p.getName(), p));
}

Map<String, PropertyVersionsBuilder> builders = new HashMap<>();

// Auto-link items if required
if (request.isAutoLinkItems()) {
final PropertyVersionsBuilder[] propertyVersionsBuilders;
try {
propertyVersionsBuilders = PomHelper.getPropertyVersionsBuilders(
this, request.getMavenProject(), request.isIncludeParent());
this, artifactFactory, request.getMavenProject(), request.isIncludeParent());
} catch (ExpressionEvaluationException | IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
Expand Down Expand Up @@ -674,7 +613,7 @@ public Map<Property, PropertyVersions> getVersionPropertiesMap(VersionProperties
if (builder == null || !builder.isAssociated()) {
getLog().debug("Property ${" + property.getName() + "}: Looks like this property is not "
+ "associated with any dependency...");
builder = new PropertyVersionsBuilder(null, property.getName(), this);
builder = new PropertyVersionsBuilder(this, null, property.getName());
}
if (!property.isAutoLinkDependencies()) {
getLog().debug("Property ${" + property.getName() + "}: Removing any autoLinkDependencies");
Expand All @@ -684,7 +623,7 @@ public Map<Property, PropertyVersions> getVersionPropertiesMap(VersionProperties
if (dependencies != null) {
for (Dependency dependency : dependencies) {
getLog().debug("Property ${" + property.getName() + "}: Adding association to " + dependency);
builder.withAssociation(this.createDependencyArtifact(dependency), false);
builder.withAssociation(artifactFactory.createArtifact(dependency), false);
}
}
try {
Expand All @@ -701,7 +640,7 @@ public Map<Property, PropertyVersions> getVersionPropertiesMap(VersionProperties
final PropertyVersions versions;
try {
if (currentVersion != null) {
builder.withCurrentVersion(DefaultArtifactVersionCache.of(currentVersion))
builder.withCurrentVersion(ArtifactVersionService.getArtifactVersion(currentVersion))
.withCurrentVersionRange(VersionRange.createFromVersionSpec(currentVersion));
}
} catch (InvalidVersionSpecificationException e) {
Expand All @@ -720,7 +659,6 @@ public Map<Property, PropertyVersions> getVersionPropertiesMap(VersionProperties
* Builder class for {@linkplain DefaultVersionsHelper}
*/
public static class Builder {
private ArtifactHandlerManager artifactHandlerManager;
private Collection<String> ignoredVersions;
private RuleSet ruleSet;
private String serverId;
Expand All @@ -729,7 +667,7 @@ public static class Builder {
private MavenSession mavenSession;
private MojoExecution mojoExecution;
private RepositorySystem repositorySystem;

private ArtifactFactory artifactFactory;
private Map<String, Wagon> wagonMap;

public Builder() {}
Expand Down Expand Up @@ -929,11 +867,6 @@ public static Optional<String> protocol(final String url) {
return pos == -1 ? empty() : of(url.substring(0, pos).trim());
}

public Builder withArtifactHandlerManager(ArtifactHandlerManager artifactHandlerManager) {
this.artifactHandlerManager = artifactHandlerManager;
return this;
}

public Builder withIgnoredVersions(Collection<String> ignoredVersions) {
this.ignoredVersions = ignoredVersions;
return this;
Expand Down Expand Up @@ -979,14 +912,19 @@ public Builder withWagonMap(Map<String, Wagon> wagonMap) {
return this;
}

public Builder withArtifactFactory(ArtifactFactory artifactFactory) {
this.artifactFactory = artifactFactory;
return this;
}

/**
* Builds the constructed {@linkplain DefaultVersionsHelper} object
* @return constructed {@linkplain DefaultVersionsHelper}
* @throws MojoExecutionException should the constructor with the RuleSet retrieval doesn't succeed
*/
public DefaultVersionsHelper build() throws MojoExecutionException {
DefaultVersionsHelper instance = new DefaultVersionsHelper(
artifactHandlerManager, repositorySystem, mavenSession, mojoExecution, log);
DefaultVersionsHelper instance =
new DefaultVersionsHelper(artifactFactory, repositorySystem, mavenSession, mojoExecution, log);
if (ruleSet != null) {
if (!isBlank(rulesUri)) {
log.warn("rulesUri is ignored if rules are specified in pom or as parameters");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.mojo.versions.model.IgnoreVersion;
import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache;
import org.eclipse.aether.version.Version;

import static org.codehaus.mojo.versions.utils.ArtifactVersionService.getArtifactVersion;

/**
* Helper class for {@link IgnoreVersion}
*/
Expand Down Expand Up @@ -81,7 +82,7 @@ private static boolean isVersionIgnoredRegex(Version version, IgnoreVersion igno

private static boolean isVersionIgnoredRange(Version version, IgnoreVersion ignoreVersion) {
try {
ArtifactVersion aVersion = DefaultArtifactVersionCache.of(version.toString());
ArtifactVersion aVersion = getArtifactVersion(version.toString());
VersionRange versionRange = VersionRange.createFromVersionSpec(ignoreVersion.getVersion());
if (versionRange.hasRestrictions()) {
return versionRange.containsVersion(aVersion);
Expand Down
Loading