Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Aether/Setting Aether Up"

m (Forced TOC)
(Updated to Aether 0.9.0.M2)
Line 1: Line 1:
{{Warning|For the time being, this article actually refers to Sonatype Aether, i.e. the predecessor of Eclipse Aether. While the artifact coordinates and class names mentioned below differ slightly from those of Eclipse Aether, the general concept for usage of Aether will remain the same once the Maven Aether Provider has adopted Eclipse Aether.}}
 
 
 
 
Aether's implementation consists of a bunch of components that need to be wired together to get a complete repository system. To satisfy different requirements and smoothly integrate into existing applications, Aether offers multiple ways to do so.
 
Aether's implementation consists of a bunch of components that need to be wired together to get a complete repository system. To satisfy different requirements and smoothly integrate into existing applications, Aether offers multiple ways to do so.
  
Line 11: Line 8:
 
<source lang="java">
 
<source lang="java">
 
import org.codehaus.plexus.DefaultPlexusContainer;
 
import org.codehaus.plexus.DefaultPlexusContainer;
import org.sonatype.aether.RepositorySystem;
+
import org.eclipse.aether.RepositorySystem;
  
 
...
 
...
Line 25: Line 22:
  
 
== JSR-330 / Guice / Sisu ==
 
== JSR-330 / Guice / Sisu ==
 
{{Note|This feature is specific to Eclipse Aether. It is primarily mentioned as a teaser for the upcoming milestone release.}}
 
  
 
Dependency injection is an established approach to component wiring and got standardized as part of [http://code.google.com/p/atinject/ JSR-330]. Aether's components are equipped with <tt>javax.inject</tt> annotations to support usage in JSR-330-enabled applications.
 
Dependency injection is an established approach to component wiring and got standardized as part of [http://code.google.com/p/atinject/ JSR-330]. Aether's components are equipped with <tt>javax.inject</tt> annotations to support usage in JSR-330-enabled applications.
  
[http://code.google.com/p/google-guice/ Google Guice] is a popular implemention of JSR-330. To ease usage of Aether in applications powered by Guice, Aether provides a ready-made Guice module that binds all the stock implementation classes.
+
[http://code.google.com/p/google-guice/ Google Guice] is a popular implemention of JSR-330. To ease usage of Aether in applications powered by Guice, Aether provides a ready-made Guice module that binds all the stock implementation classes. See our [http://git.eclipse.org/c/aether/aether-demo.git/ runnable demo snippets] for a complete example using Guice.
  
 
For those seeking the simplicity of having components be discovered from the classpath as opposed to manually binding them, [http://www.eclipse.org/sisu/ Sisu] can help. Among others, it extends Guice with automatic/dynamic component discovery. Aether's JARs are equipped with Sisu index files to enable optimal performance during component discovery.
 
For those seeking the simplicity of having components be discovered from the classpath as opposed to manually binding them, [http://www.eclipse.org/sisu/ Sisu] can help. Among others, it extends Guice with automatic/dynamic component discovery. Aether's JARs are equipped with Sisu index files to enable optimal performance during component discovery.
Line 38: Line 33:
 
Sometimes, the overhead of using a full-blown dependency injection container is undesirable. To get an instance of the repository system without an IoC container, the classes from the default implementation of Aether provide no-arg constructors and setters to manually wire the components together. But since this isn't really fun to code, the repository system additionally supports wiring via a lightweight service locator pattern.
 
Sometimes, the overhead of using a full-blown dependency injection container is undesirable. To get an instance of the repository system without an IoC container, the classes from the default implementation of Aether provide no-arg constructors and setters to manually wire the components together. But since this isn't really fun to code, the repository system additionally supports wiring via a lightweight service locator pattern.
  
This service locator infrastructure consists of merely two small interfaces, namely <tt>org.sonatype.aether.spi.locator.Service</tt> and <tt>org.sonatype.aether.spi.locator.ServiceLocator</tt>. The components themselves implement the <tt>Service</tt> interface, and the client of the repository system provides to them an implementation of the <tt>ServiceLocator</tt> to query other components from.
+
This service locator infrastructure consists of merely two small interfaces, namely <tt>org.eclipse.aether.spi.locator.Service</tt> and <tt>org.eclipse.aether.spi.locator.ServiceLocator</tt>. The components themselves implement the <tt>Service</tt> interface, and the client of the repository system provides to them an implementation of the <tt>ServiceLocator</tt> to query other components from.
  
 
The module <tt>maven-aether-provider</tt> from the [http://maven.apache.org/ Apache Maven] project provides a simple service locator for Aether whose usage looks like shown below:
 
The module <tt>maven-aether-provider</tt> from the [http://maven.apache.org/ Apache Maven] project provides a simple service locator for Aether whose usage looks like shown below:
  
 
<source lang="java">
 
<source lang="java">
import org.apache.maven.repository.internal.DefaultServiceLocator;
+
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.sonatype.aether.connector.wagon.WagonProvider;
+
import org.eclipse.aether.connector.wagon.WagonProvider;
import org.sonatype.aether.connector.wagon.WagonRepositoryConnectorFactory;
+
import org.eclipse.aether.connector.wagon.WagonRepositoryConnectorFactory;
  
 
...
 
...
 
     private static RepositorySystem newRepositorySystem()
 
     private static RepositorySystem newRepositorySystem()
 
     {
 
     {
         DefaultServiceLocator locator = new DefaultServiceLocator();
+
         DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
 
         locator.setServices( WagonProvider.class, new ManualWagonProvider() );
 
         locator.setServices( WagonProvider.class, new ManualWagonProvider() );
 
         locator.addService( RepositoryConnectorFactory.class, WagonRepositoryConnectorFactory.class );
 
         locator.addService( RepositoryConnectorFactory.class, WagonRepositoryConnectorFactory.class );
Line 59: Line 54:
 
</source>
 
</source>
  
The <tt>DefaultServiceLocator</tt> mentioned above already knows about all the components from <tt>aether-impl</tt> and <tt>maven-aether-provider</tt>, so the remaining missing bits that it needs to be told about are zero or more repository connectors. Once the locator's internal service registry is populated, the call to <tt>getService()</tt> will create the repository system and recursively initialize its sub components.
+
The <tt>DefaultServiceLocator</tt> created via <tt>MavenRepositorySystemUtils</tt> already knows about all the components from <tt>aether-impl</tt> and <tt>maven-aether-provider</tt>, so the remaining missing bits that it needs to be told about are zero or more repository connectors. Once the locator's internal service registry is populated, the call to <tt>getService()</tt> will create the repository system and recursively initialize its sub components.

Revision as of 19:05, 22 April 2013

Aether's implementation consists of a bunch of components that need to be wired together to get a complete repository system. To satisfy different requirements and smoothly integrate into existing applications, Aether offers multiple ways to do so.

Plexus

You can use a Plexus container (or any other dependency injection container that supports Plexus components like Sisu). For instance, assuming you add a dependency on org.sonatype.sisu:sisu-inject-plexus:2.3.0 to your POM, the following code fragment discovers the various Aether components from the thread context class loader and wires the system together:

import org.codehaus.plexus.DefaultPlexusContainer;
import org.eclipse.aether.RepositorySystem;
 
...
    private static RepositorySystem newRepositorySystem()
        throws Exception
    {
        return new DefaultPlexusContainer().lookup( RepositorySystem.class );
    }
...

We mostly mention this Plexus-based system setup here for completeness. The Plexus container is no longer maintained and users of it should start to migrate to alternatives like JSR-330.

JSR-330 / Guice / Sisu

Dependency injection is an established approach to component wiring and got standardized as part of JSR-330. Aether's components are equipped with javax.inject annotations to support usage in JSR-330-enabled applications.

Google Guice is a popular implemention of JSR-330. To ease usage of Aether in applications powered by Guice, Aether provides a ready-made Guice module that binds all the stock implementation classes. See our runnable demo snippets for a complete example using Guice.

For those seeking the simplicity of having components be discovered from the classpath as opposed to manually binding them, Sisu can help. Among others, it extends Guice with automatic/dynamic component discovery. Aether's JARs are equipped with Sisu index files to enable optimal performance during component discovery.

Service Locator

Sometimes, the overhead of using a full-blown dependency injection container is undesirable. To get an instance of the repository system without an IoC container, the classes from the default implementation of Aether provide no-arg constructors and setters to manually wire the components together. But since this isn't really fun to code, the repository system additionally supports wiring via a lightweight service locator pattern.

This service locator infrastructure consists of merely two small interfaces, namely org.eclipse.aether.spi.locator.Service and org.eclipse.aether.spi.locator.ServiceLocator. The components themselves implement the Service interface, and the client of the repository system provides to them an implementation of the ServiceLocator to query other components from.

The module maven-aether-provider from the Apache Maven project provides a simple service locator for Aether whose usage looks like shown below:

import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.connector.wagon.WagonProvider;
import org.eclipse.aether.connector.wagon.WagonRepositoryConnectorFactory;
 
...
    private static RepositorySystem newRepositorySystem()
    {
        DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
        locator.setServices( WagonProvider.class, new ManualWagonProvider() );
        locator.addService( RepositoryConnectorFactory.class, WagonRepositoryConnectorFactory.class );
 
        return locator.getService( RepositorySystem.class );
    }
...

The DefaultServiceLocator created via MavenRepositorySystemUtils already knows about all the components from aether-impl and maven-aether-provider, so the remaining missing bits that it needs to be told about are zero or more repository connectors. Once the locator's internal service registry is populated, the call to getService() will create the repository system and recursively initialize its sub components.

Back to the top