Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aether-users] Downloading the latest Snapshot

Hello everyone
 
I am having two little problem with the Aether-API. I am trying to download/resolve the latest version of some artifacts.
 
According to the examples ( http://git.eclipse.org/c/aether/aether-demo.git/tree/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindNewestVersion.java ) it is possible to get the latest version when using [0,) as version-coordinate. I am following the example but when using this snippet I get a ArtifactNotFoundException. When I use the actual version (1.3.0-SNAPSHOT) the VersionRange gets resolved.
 
Just in case I missed somethinig, here is my code (using Guice for setup). I add my local maven-repository as a remote because I want to test with some artifacts that are not yet in our projects nexus. But this shouldnt matter at all and it doesnt change anything when I remove it.
 
public class GuiceRepositorySystemFactory
{
      public static RepositorySystem newRepositorySystem()
      {
            return Guice.createInjector(new AetherModule()).getInstance(RepositorySystem.class);
      }
}
----------------------------------------------------------------------
 
public class AetherModule extends AbstractModule
{
 
      @Override
      protected void configure()
      {
            install(new MavenAetherModule());
            bind(RepositoryConnectorFactory.class).annotatedWith(Names.named("basic")).to(BasicRepositoryConnectorFactory.class);
            bind(TransporterFactory.class).annotatedWith(Names.named("file")).to(FileTransporterFactory.class);
            bind(TransporterFactory.class).annotatedWith(Names.named("http")).to(HttpTransporterFactory.class);
      }
 
 
      @Provides
      @Singleton
      Set<RepositoryConnectorFactory> provideRepositoryConnectorFactories(@Named("basic") RepositoryConnectorFactory basic)
      {
            Set<RepositoryConnectorFactory> factories = new HashSet<RepositoryConnectorFactory>();
            factories.add(basic);
            return Collections.unmodifiableSet(factories);
      }
 
 
      @Provides
      @Singleton
      Set<TransporterFactory> provideTransporterFactories(@Named("file") TransporterFactory file, @Named("http") TransporterFactory http)
      {
            Set<TransporterFactory> factories = new HashSet<TransporterFactory>();
            factories.add(file);
            factories.add(http);
            return Collections.unmodifiableSet(factories);
      }
}
----------------------------------------------------------------------
 
public class AetherResolver
{
      private static RepositorySystemSession newSession(RepositorySystem system)
      {
            DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
 
            LocalRepository localRepo = new LocalRepository("C:/Temp/testRepo");
            session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
            return session;
      }
 
 
      public List<URL> resolveURLs()
      {
            try
            {
                  RepositorySystem system = GuiceRepositorySystemFactory.newRepositorySystem();
                  RepositorySystemSession session = newSession(system);
 
                  List<RemoteRepository> remotes = Arrays.asList(
                             new RemoteRepository.Builder(
                                         "remote",
                                         "default",
                                         "http://someremote/blubb").build(),
                             new RemoteRepository.Builder(
                                         "local",
                                         "default",
                                         new File("C:/Users/name/.m2/repository").toURI().toURL().toString()).build());
 
                  Artifact artifact = new DefaultArtifact("groupid", "artifact", "jar", "[0,)");
                  //Artifact artifact = new DefaultArtifact("groupid:artifact:1.3.0-SNAPSHOT");
 
                  VersionRangeRequest rangeRequest = new VersionRangeRequest();
                  rangeRequest.setArtifact(artifact);
                  rangeRequest.setRepositories(remotes);
 
                  VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
                  Version newest = rangeResult.getHighestVersion();
                  System.out.println("Highest Version: " + newest);
 
 
                  artifact.setVersion(newest.toString());
 
                  ArtifactRequest artifactRequest = new ArtifactRequest();
                  artifactRequest.setArtifact(artifact);
                  artifactRequest.setRepositories(remotes);
                  ArtifactResult result = system.resolveArtifact(session, artifactRequest);
                  // TODO
                  return Arrays.asList(result.getArtifact().getFile().toURI().toURL());
            } catch (Exception e)
            {
                  e.printStackTrace();
            }
 
            return Collections.emptyList();
      }
}
 

Back to the top