Adding repository registry

This commit is contained in:
Martin Stockhammer 2017-10-02 22:21:26 +02:00
parent 656af5ce4d
commit 93af7e9457
5 changed files with 205 additions and 2 deletions

View File

@ -169,7 +169,7 @@
</execution>
</executions>
<configuration>
<version>1.4.2</version>
<version>3.0.0</version>
<models>
<model>src/main/mdo/configuration.mdo</model>
</models>

View File

@ -30,6 +30,10 @@
<value>org.apache.archiva.configuration</value>
</default>
</defaults>
<versionDefinition>
<type>field</type>
<value>version</value>
</versionDefinition>
<classes>
<class rootElement="true" xml.tagName="configuration">
<name>Configuration</name>
@ -431,6 +435,16 @@
The repository identifier.
</description>
</field>
<field>
<name>type</name>
<version>3.0.0+</version>
<type>String</type>
<required>true</required>
<defaultValue>MAVEN</defaultValue>
<description>
The repository type. Currently only MAVEN type is known.
</description>
</field>
<field>
<name>name</name>
<version>1.0.0+</version>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<version>3</version>
<version>3.0.0</version>
<managedRepositories>
<managedRepository>
<id>internal</id>

View File

@ -0,0 +1,40 @@
package org.apache.archiva.repository;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import java.util.Set;
/**
*
* This interface must be implemented by the repository implementations. These
* are responsible for creating the instances.
*
*/
public interface RepositoryProvider
{
Set<RepositoryType> provides();
ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration);
RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration);
}

View File

@ -0,0 +1,149 @@
package org.apache.archiva.repository;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Registry for repositories
*/
@Service("repositoryRegistry")
public class RepositoryRegistry
{
/**
* We inject all repository providers
*/
@Inject
List<RepositoryProvider> repositoryProviders;
@Inject
ArchivaConfiguration archivaConfiguration;
private Map<String, ManagedRepository> managedRepositories = new HashMap<>( );
private Map<String, RemoteRepository> remoteRepositories = new HashMap<>( );
@PostConstruct
private void initialize() {
managedRepositories = getManagedRepositoriesFromConfig();
remoteRepositories = getRemoteRepositoriesFromConfig();
}
private Map<RepositoryType, RepositoryProvider> getProviderMap() {
Map<RepositoryType, RepositoryProvider> map = new HashMap<>( );
if (repositoryProviders!=null) {
for(RepositoryProvider provider : repositoryProviders) {
for (RepositoryType type : provider.provides()) {
map.put(type, provider);
}
}
}
return map;
}
private Map<String,ManagedRepository> getManagedRepositoriesFromConfig() {
List<ManagedRepositoryConfiguration> managedRepoConfigs =
getArchivaConfiguration().getConfiguration().getManagedRepositories();
if ( managedRepoConfigs == null )
{
return Collections.emptyMap();
}
Map<String,ManagedRepository> managedRepos = new LinkedHashMap<>( managedRepoConfigs.size() );
Map<RepositoryType, RepositoryProvider> providerMap = getProviderMap( );
for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
{
RepositoryType repositoryType = RepositoryType.valueOf( repoConfig.getType( ) );
if (providerMap.containsKey( repositoryType )) {
managedRepos.put(repoConfig.getId(), providerMap.get(repositoryType).createManagedInstance( repoConfig ));
}
}
return managedRepos;
}
private Map<String,RemoteRepository> getRemoteRepositoriesFromConfig() {
List<RemoteRepositoryConfiguration> remoteRepoConfigs =
getArchivaConfiguration().getConfiguration().getRemoteRepositories();
if ( remoteRepoConfigs == null )
{
return Collections.emptyMap();
}
Map<String,RemoteRepository> remoteRepos = new LinkedHashMap<>( remoteRepoConfigs.size() );
Map<RepositoryType, RepositoryProvider> providerMap = getProviderMap( );
for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
{
RepositoryType repositoryType = RepositoryType.valueOf( repoConfig.getType( ) );
if (providerMap.containsKey( repositoryType )) {
remoteRepos.put(repoConfig.getId(), providerMap.get(repositoryType).createRemoteInstance( repoConfig ));
}
}
return remoteRepos;
}
private ArchivaConfiguration getArchivaConfiguration() {
return this.archivaConfiguration;
}
public List<Repository> getRepositories() {
ArrayList<Repository> li = new ArrayList<>( );
li.addAll(managedRepositories.values());
li.addAll(remoteRepositories.values());
return Collections.unmodifiableList( li );
}
public List<ManagedRepository> getManagedRepositories() {
return Collections.unmodifiableList( new ArrayList(managedRepositories.values()) );
}
public List<RemoteRepository> getRemoteRepositories() {
return Collections.unmodifiableList( new ArrayList(remoteRepositories.values()) );
}
public Repository getRepository(String repoId) {
return null;
}
public ManagedRepository getManagedRepository(String repoId) {
return null;
}
public RemoteRepository getRemoteRepository(String repoId) {
return null;
}
}