1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.repository.aether.internal

File AetherExtensionRepositoryFactory.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
18
4
1
122
78
8
0.44
4.5
4
2

Classes

Class Line # Actions
AetherExtensionRepositoryFactory 53 18 0% 8 2
0.923076992.3%
 

Contributing tests

This file is covered by 21 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.repository.aether.internal;
21   
22    import java.util.ArrayList;
23    import java.util.Collection;
24    import java.util.List;
25   
26    import javax.inject.Inject;
27    import javax.inject.Named;
28    import javax.inject.Provider;
29    import javax.inject.Singleton;
30   
31    import org.codehaus.plexus.PlexusContainer;
32    import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
33    import org.eclipse.aether.RepositorySystem;
34    import org.eclipse.aether.repository.RemoteRepository;
35    import org.xwiki.component.annotation.Component;
36    import org.xwiki.component.manager.ComponentManager;
37    import org.xwiki.component.phase.Initializable;
38    import org.xwiki.component.phase.InitializationException;
39    import org.xwiki.extension.ExtensionManagerConfiguration;
40    import org.xwiki.extension.repository.AbstractExtensionRepositoryFactory;
41    import org.xwiki.extension.repository.ExtensionRepository;
42    import org.xwiki.extension.repository.ExtensionRepositoryDescriptor;
43    import org.xwiki.extension.repository.ExtensionRepositoryException;
44    import org.xwiki.extension.repository.ExtensionRepositoryManager;
45   
46    /**
47    * @version $Id: 81a55f3a16b33bcf2696d0cac493b25c946b6ee4 $
48    * @since 4.0M1
49    */
50    @Component
51    @Singleton
52    @Named("maven")
 
53    public class AetherExtensionRepositoryFactory extends AbstractExtensionRepositoryFactory implements Initializable
54    {
55    @Inject
56    private ComponentManager componentManager;
57   
58    @Inject
59    private Provider<PlexusContainer> plexusProvider;
60   
61    @Inject
62    private ExtensionManagerConfiguration configuration;
63   
64    @Inject
65    private Provider<ExtensionRepositoryManager> repositoryManagerProvider;
66   
67    private RepositorySystem repositorySystem;
68   
 
69  25 toggle @Override
70    public void initialize() throws InitializationException
71    {
72  25 try {
73  25 this.repositorySystem = this.plexusProvider.get().lookup(RepositorySystem.class);
74    } catch (ComponentLookupException e) {
75  0 throw new InitializationException("Failed to lookup RepositorySystem", e);
76    }
77    }
78   
 
79  126 toggle public XWikiRepositorySystemSession createRepositorySystemSession()
80    {
81  126 XWikiRepositorySystemSession session = new XWikiRepositorySystemSession(this.repositorySystem);
82   
83  126 session.setUserAgent(this.configuration.getUserAgent());
84   
85  126 return session;
86    }
87   
 
88  46 toggle @Override
89    public ExtensionRepository createRepository(ExtensionRepositoryDescriptor repositoryDescriptor)
90    throws ExtensionRepositoryException
91    {
92  46 try {
93  46 return new AetherExtensionRepository(repositoryDescriptor, this, this.plexusProvider.get(),
94    this.componentManager);
95    } catch (Exception e) {
96  0 throw new ExtensionRepositoryException("Failed to create repository [" + repositoryDescriptor + "]", e);
97    }
98    }
99   
 
100  51 toggle List<RemoteRepository> getAllMavenRepositories(RemoteRepository firstRepository)
101    {
102  51 Collection<ExtensionRepository> extensionRepositories = this.repositoryManagerProvider.get().getRepositories();
103   
104  51 List<RemoteRepository> reposirories = new ArrayList<RemoteRepository>(extensionRepositories.size());
105   
106    // Put first repository
107  51 reposirories.add(firstRepository);
108   
109    // Add other repositories (and filter first one)
110  51 for (ExtensionRepository extensionRepository : extensionRepositories) {
111  92 if (extensionRepository instanceof AetherExtensionRepository) {
112  90 RemoteRepository repository = ((AetherExtensionRepository) extensionRepository).getRemoteRepository();
113   
114  90 if (firstRepository != repository) {
115  39 reposirories.add(repository);
116    }
117    }
118    }
119   
120  51 return reposirories;
121    }
122    }