View Javadoc
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.io.File;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import org.eclipse.aether.RepositorySystem;
26  import org.eclipse.aether.RepositorySystemSession.CloseableSession;
27  import org.eclipse.aether.artifact.Artifact;
28  import org.eclipse.aether.artifact.DefaultArtifact;
29  import org.eclipse.aether.repository.RemoteRepository;
30  import org.eclipse.aether.resolution.VersionRangeRequest;
31  import org.eclipse.aether.resolution.VersionRangeResult;
32  import org.eclipse.aether.version.Version;
33  import org.junit.jupiter.api.Test;
34  
35  import static org.junit.jupiter.api.Assertions.*;
36  
37  public class RepositorySystemSupplierTest {
38      private final RepositorySystemSupplier subject = new RepositorySystemSupplier();
39  
40      @Test
41      void smoke() throws Exception {
42          try (RepositorySystem system = subject.get();
43                  CloseableSession session = new SessionBuilderSupplier(system)
44                          .get()
45                          .withLocalRepositoryBaseDirectories(new File("target/local-repo"))
46                          .build()) {
47              Artifact artifact = new DefaultArtifact("org.apache.maven.resolver:maven-resolver-util:[0,)");
48              VersionRangeRequest rangeRequest = new VersionRangeRequest();
49              rangeRequest.setArtifact(artifact);
50              rangeRequest.setRepositories(Collections.singletonList(
51                      new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2/")
52                              .build()));
53              VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
54              List<Version> versions = rangeResult.getVersions();
55  
56              // As of 2023-11-14, Maven Central has 36 versions of this artifact (and it will just grow)
57              assertTrue(versions.size() >= 36);
58              System.out.println("Available " + versions.size() + " versions: " + versions);
59          }
60      }
61  }