Skip to content

Commit

Permalink
removed Maven and Numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 committed Jan 22, 2025
1 parent 8acbf6d commit 24089ad
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,14 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.codehaus.mojo.versions.model.IgnoreVersion;
import org.codehaus.mojo.versions.ordering.SegmentCounter;
import org.codehaus.mojo.versions.rule.RuleService;
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.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.repository.AuthenticationContext;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.repository.RepositoryPolicy;
import org.eclipse.aether.resolution.ArtifactRequest;
Expand All @@ -76,7 +72,6 @@
import org.eclipse.aether.resolution.VersionRangeResolutionException;

import static java.util.Objects.requireNonNull;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import static org.apache.maven.RepositoryUtils.toArtifact;
Expand Down Expand Up @@ -229,8 +224,8 @@ public ArtifactVersions lookupArtifactVersions(
}
}

public SortedSet<ArtifactVersion> resolveAssociatedVersions(
Set<ArtifactAssociation> associations, SegmentCounter versionComparator) throws VersionRetrievalException {
public SortedSet<ArtifactVersion> resolveAssociatedVersions(Set<ArtifactAssociation> associations)
throws VersionRetrievalException {
SortedSet<ArtifactVersion> versions = null;
for (ArtifactAssociation association : associations) {
final ArtifactVersions associatedVersions =
Expand Down Expand Up @@ -516,54 +511,6 @@ public static class Builder {

public Builder() {}

private Optional<ProxyInfo> getProxyInfo(RemoteRepository repository) {
return ofNullable(repository.getProxy()).map(proxy -> new ProxyInfo() {
{
setHost(proxy.getHost());
setPort(proxy.getPort());
setType(proxy.getType());
ofNullable(proxy.getAuthentication()).ifPresent(auth -> {
try (AuthenticationContext authCtx =
AuthenticationContext.forProxy(mavenSession.getRepositorySession(), repository)) {
ofNullable(authCtx.get(AuthenticationContext.USERNAME))
.ifPresent(this::setUserName);
ofNullable(authCtx.get(AuthenticationContext.PASSWORD))
.ifPresent(this::setPassword);
ofNullable(authCtx.get(AuthenticationContext.NTLM_DOMAIN))
.ifPresent(this::setNtlmDomain);
ofNullable(authCtx.get(AuthenticationContext.NTLM_WORKSTATION))
.ifPresent(this::setNtlmHost);
}
});
}
});
}

private Optional<AuthenticationInfo> getAuthenticationInfo(RemoteRepository repository) {
return ofNullable(repository.getAuthentication()).map(authentication -> new AuthenticationInfo() {
{
try (AuthenticationContext authCtx =
AuthenticationContext.forRepository(mavenSession.getRepositorySession(), repository)) {
ofNullable(authCtx.get(AuthenticationContext.USERNAME)).ifPresent(this::setUserName);
ofNullable(authCtx.get(AuthenticationContext.PASSWORD)).ifPresent(this::setPassword);
ofNullable(authCtx.get(AuthenticationContext.PRIVATE_KEY_PASSPHRASE))
.ifPresent(this::setPassphrase);
ofNullable(authCtx.get(AuthenticationContext.PRIVATE_KEY_PATH))
.ifPresent(this::setPrivateKey);
}
}
});
}

private org.apache.maven.wagon.repository.Repository wagonRepository(RemoteRepository repository) {
return new org.apache.maven.wagon.repository.Repository(repository.getId(), repository.getUrl());
}

public static Optional<String> protocol(final String url) {
int pos = url.indexOf(":");
return pos == -1 ? empty() : of(url.substring(0, pos).trim());
}

public Builder withLog(Log log) {
this.log = log;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* under the License.
*/

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
Expand All @@ -40,9 +39,7 @@
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.versions.ordering.BoundArtifactVersion;
import org.codehaus.mojo.versions.ordering.DefaultSegmentCounter;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.ordering.SegmentCounter;
import org.codehaus.mojo.versions.utils.ArtifactVersionService;

import static java.util.Optional.empty;
Expand All @@ -66,9 +63,7 @@ public class PropertyVersions extends AbstractVersionDetails {
*
* @since 1.0-beta-1
*/
private final SortedSet<ArtifactVersion> versions;

private final PropertySegmentCounter comparator;
private final SortedSet<ArtifactVersion> allVersions;

private final Log log;

Expand All @@ -79,8 +74,7 @@ public class PropertyVersions extends AbstractVersionDetails {
this.name = name;
this.log = log;
this.associations = new TreeSet<>(associations);
this.comparator = new PropertySegmentCounter();
this.versions = helper.resolveAssociatedVersions(associations, comparator);
this.allVersions = helper.resolveAssociatedVersions(associations);
}

public ArtifactAssociation[] getAssociations() {
Expand All @@ -97,7 +91,7 @@ public ArtifactAssociation[] getAssociations() {
* @since 1.0-alpha-3
*/
public ArtifactVersion[] getVersions(Collection<Artifact> artifacts) {
List<ArtifactVersion> result = new ArrayList<>();
SortedSet<ArtifactVersion> result = new TreeSet<>();
// go through all the associations
// see if they are met from the collection
// add the version if they are
Expand Down Expand Up @@ -142,7 +136,7 @@ public ArtifactVersion[] getVersions(Collection<Artifact> artifacts) {
continue versions;
}
}
return asArtifactVersionArray(result);
return result.toArray(new ArtifactVersion[0]);
}

/**
Expand All @@ -152,30 +146,10 @@ public ArtifactVersion[] getVersions(Collection<Artifact> artifacts) {
* @param includeSnapshots Whether to include snapshot versions in our search.
* @return The (possibly empty) array of versions.
*/
public synchronized ArtifactVersion[] getVersions(boolean includeSnapshots) {
Set<ArtifactVersion> result;
if (includeSnapshots) {
result = versions;
} else {
result = new TreeSet<>();
for (ArtifactVersion candidate : versions) {
if (ArtifactUtils.isSnapshot(candidate.toString())) {
continue;
}
result.add(candidate);
}
}
return asArtifactVersionArray(result);
}

private ArtifactVersion[] asArtifactVersionArray(Collection<ArtifactVersion> result) {
if (result == null || result.isEmpty()) {
return new ArtifactVersion[0];
} else {
final ArtifactVersion[] answer = result.toArray(new ArtifactVersion[0]);
Arrays.sort(answer);
return answer;
}
public ArtifactVersion[] getVersions(boolean includeSnapshots) {
return allVersions.stream()
.filter(v -> includeSnapshots || !ArtifactUtils.isSnapshot(v.toString()))
.toArray(ArtifactVersion[]::new);
}

/**
Expand Down Expand Up @@ -327,18 +301,4 @@ public ArtifactVersion getNewestVersion(
}
return result;
}

private final class PropertySegmentCounter implements SegmentCounter {

/**
* {@inheritDoc}
*/
@Override
public int getSegmentCount(ArtifactVersion v) {
if (!isAssociated()) {
throw new IllegalStateException("Cannot compare versions for a property with no associations");
}
return DefaultSegmentCounter.INSTANCE.getSegmentCount(v);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.versions.ordering.SegmentCounter;

/**
* Helper class that provides common functionality required by both the mojos and the reports.
Expand Down Expand Up @@ -350,9 +349,8 @@ public VersionPropertiesMapRequest build() {
/**
* Resolves {@link ArtifactVersions} for a set of artifact associations
* @param associations set of artifact versions
* @param versionComparator comparator
* @return set of resolved associations
*/
SortedSet<ArtifactVersion> resolveAssociatedVersions(
Set<ArtifactAssociation> associations, SegmentCounter versionComparator) throws VersionRetrievalException;
SortedSet<ArtifactVersion> resolveAssociatedVersions(Set<ArtifactAssociation> associations)
throws VersionRetrievalException;
}
2 changes: 1 addition & 1 deletion versions-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
<pomExcludes>
<!--
! This test is not really intended as part of regular integration test suite
! as it highly depends on the minute conditions of the build cluster,
! as it highly depends on the state of the build cluster,
! internet connection speed (since retrieval times are included in the timeout)
! or individual machine where it's being tested.
! Not deleting as it might be helpful with assessing performance measurements.
Expand Down

0 comments on commit 24089ad

Please sign in to comment.