| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
* or more contributor license agreements. See the NOTICE file |
| 4 |
* distributed with this work for additional information |
| 5 |
* regarding copyright ownership. The ASF licenses this file |
| 6 |
* to you under the Apache License, Version 2.0 (the |
| 7 |
* "License"); you may not use this file except in compliance |
| 8 |
* with the License. You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
*/ |
| 19 |
package org.eclipse.aether.supplier; |
| 20 |
|
| 21 |
import java.util.Collections; |
| 22 |
import java.util.List; |
| 23 |
|
| 24 |
import org.apache.maven.repository.internal.MavenRepositorySystemUtils; |
| 25 |
import org.eclipse.aether.DefaultRepositorySystemSession; |
| 26 |
import org.eclipse.aether.RepositorySystem; |
| 27 |
import org.eclipse.aether.RepositorySystemSession; |
| 28 |
import org.eclipse.aether.artifact.Artifact; |
| 29 |
import org.eclipse.aether.artifact.DefaultArtifact; |
| 30 |
import org.eclipse.aether.repository.LocalRepository; |
| 31 |
import org.eclipse.aether.repository.RemoteRepository; |
| 32 |
import org.eclipse.aether.resolution.VersionRangeRequest; |
| 33 |
import org.eclipse.aether.resolution.VersionRangeResult; |
| 34 |
import org.eclipse.aether.version.Version; |
| 35 |
import org.junit.Test; |
| 36 |
|
| 37 |
import static org.hamcrest.MatcherAssert.assertThat; |
| 38 |
import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
| 39 |
import static org.hamcrest.Matchers.hasSize; |
| 40 |
|
| 41 |
public class RepositorySystemSupplierTest { |
| 42 |
private final RepositorySystemSupplier subject = new RepositorySystemSupplier(); |
| 43 |
|
| 44 |
public static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system) { |
| 45 |
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); |
| 46 |
LocalRepository localRepo = new LocalRepository("target/local-repo"); |
| 47 |
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo)); |
| 48 |
return session; |
| 49 |
} |
| 50 |
|
| 51 |
@Test |
| 52 |
public void smoke() throws Exception { |
| 53 |
RepositorySystem system = subject.get(); |
| 54 |
RepositorySystemSession session = newRepositorySystemSession(system); |
| 55 |
|
| 56 |
Artifact artifact = new DefaultArtifact("org.apache.maven.resolver:maven-resolver-util:[0,)"); |
| 57 |
VersionRangeRequest rangeRequest = new VersionRangeRequest(); |
| 58 |
rangeRequest.setArtifact(artifact); |
| 59 |
rangeRequest.setRepositories(Collections.singletonList( |
| 60 |
new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2/").build())); |
| 61 |
VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest); |
| 62 |
List<Version> versions = rangeResult.getVersions(); |
| 63 |
|
| 64 |
// As of 2023-08-01, Maven Central has 33 versions of this artifact (and it will just grow) |
| 65 |
assertThat(versions, hasSize(greaterThanOrEqualTo(33))); |
| 66 |
System.out.println("Available versions " + versions); |
| 67 |
} |
| 68 |
} |