]> source.dussan.org Git - archiva.git/commitdiff
Adding repository registry
authorMartin Stockhammer <martin_s@apache.org>
Mon, 2 Oct 2017 20:21:26 +0000 (22:21 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Mon, 2 Oct 2017 20:21:26 +0000 (22:21 +0200)
archiva-modules/archiva-base/archiva-configuration/pom.xml
archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
archiva-modules/archiva-base/archiva-configuration/src/main/resources/org/apache/archiva/configuration/default-archiva.xml
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryProvider.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java [new file with mode: 0644]

index 6eb89237e32966f785aa387d21d38039282eb660..08675581bb25d035774146e90410b090ec5affd2 100644 (file)
           </execution>
         </executions>
         <configuration>
-          <version>1.4.2</version>
+          <version>3.0.0</version>
           <models>
             <model>src/main/mdo/configuration.mdo</model>
           </models>
index eac0aa2c95149d8af4770b85d12283d3285bd893..5af50af7f5edccb429e8e64a2b53535db5c76ae3 100644 (file)
       <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>
             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>
index 88beda2e01be1cd93d05a0444c15f26b34e5b67f..88144df1cd1877f07e4ed61f57530bd001844dac 100644 (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>
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryProvider.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryProvider.java
new file mode 100644 (file)
index 0000000..fdd2153
--- /dev/null
@@ -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);
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java
new file mode 100644 (file)
index 0000000..eaa3daf
--- /dev/null
@@ -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;
+    }
+
+}