Adapt to changes in Aether
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 20 Feb 2015 16:26:38 +0000 (16:26 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 20 Feb 2015 16:26:38 +0000 (16:26 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@7931 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc.support/src/org/argeo/slc/aether/spring/RemoteRepositoryFactory.java

index eddcea720fb64a4536e9c27ec679d31c10f47346..7223c78cb59d478c2dd4d5f5bd7596d421854a83 100644 (file)
 package org.argeo.slc.aether.spring;
 
 import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.util.repository.AuthenticationBuilder;
 import org.springframework.beans.factory.BeanNameAware;
 import org.springframework.beans.factory.FactoryBean;
 
 /** Simplifies the definition of a remote factory using Spring */
-public class RemoteRepositoryFactory implements BeanNameAware, FactoryBean {
+public class RemoteRepositoryFactory implements BeanNameAware,
+               FactoryBean<RemoteRepository> {
        private String beanName;
        private String id;
        private String url;
@@ -28,16 +30,17 @@ public class RemoteRepositoryFactory implements BeanNameAware, FactoryBean {
        private String username;
        private String password;
 
-       public Object getObject() throws Exception {
-               RemoteRepository remoteRepository = new RemoteRepository.Builder(
-                               id != null ? id : beanName, type, url).build();
-               // FIXME Adapt to changes in Aether
-               // if (username != null) {
-               // Authentication authentication = new Authentication(username,
-               // password);
-               // remoteRepository.setAuthentication(authentication);
-               // }
-               return null;
+       public RemoteRepository getObject() throws Exception {
+               RemoteRepository.Builder builder = new RemoteRepository.Builder(
+                               id != null ? id : beanName, type, url);
+               if (username != null) {
+                       AuthenticationBuilder authBuilder = new AuthenticationBuilder();
+                       authBuilder.addUsername(username);
+                       authBuilder.addPassword(password);
+                       builder.setAuthentication(authBuilder.build());
+               }
+               RemoteRepository remoteRepository = builder.build();
+               return remoteRepository;
        }
 
        public Class<?> getObjectType() {