import org.apache.archiva.repository.validation.RepositoryChecker;
import org.apache.archiva.repository.validation.RepositoryValidator;
import org.apache.archiva.repository.validation.ValidationError;
-import org.apache.archiva.repository.validation.ValidationResponse;
import java.util.Collection;
import java.util.List;
* Initializes the repository. E.g. starts scheduling and activate additional processes.
* @param repository the repository to initialize
*/
- void initialize( R repository );
+ void activateRepository( R repository );
/**
* Creates new instances from the archiva configuration. The instances are not registered in the registry.
R newInstance( RepositoryType type, String id ) throws RepositoryException;
/**
- * Creates a new instance and updates the given configuration object.
+ * Creates a new instance based on the given configuration instance. The instance is not activated and not registered.
*
* @param repositoryConfiguration the configuration instance
* @return a newly created instance
void remove( String id, Configuration configuration ) throws RepositoryException;
/**
- * Returns the repository with the given identifier or <code>null</code>, if it is not registered.
+ * Returns the repository with the given identifier or <code>null</code>, if no repository is registered
+ * with the given id.
*
* @param id the repository id
- * @return if the retrieval failed
+ * @return the repository instance or <code>null</code>
*/
R get( String id );
boolean has( String id );
/**
- * Initializes
+ * Initializes the handler. This method must be called before using the repository handler.
*/
void init( );
/**
- * Closes the handler
+ * Closes the handler. After closing, the repository handler instance is not usable anymore.
*/
void close( );
import org.apache.archiva.repository.validation.RepositoryChecker;
import org.apache.archiva.repository.validation.RepositoryValidator;
import org.apache.archiva.repository.validation.ValidationError;
-import org.apache.archiva.repository.validation.ValidationResponse;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
this.repositoryGroups.putAll( newInstancesFromConfig( ) );
for ( RepositoryGroup group : this.repositoryGroups.values( ) )
{
- initialize( group );
+ activateRepository( group );
}
}
}
@Override
- public void initialize( RepositoryGroup repositoryGroup )
+ public void activateRepository( RepositoryGroup repositoryGroup )
{
StorageAsset indexDirectory = getMergedIndexDirectory( repositoryGroup );
if ( !indexDirectory.exists( ) )
configuration.addRepositoryGroup( newCfg );
configurationHandler.save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
setLastState( repositoryGroup, RepositoryState.SAVED );
- initialize( repositoryGroup );
+ activateRepository( repositoryGroup );
}
finally
{
configurationHandler.save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
updateReferences( currentRepository, repositoryGroupConfiguration );
setLastState( currentRepository, RepositoryState.REFERENCES_SET );
- initialize( currentRepository );
+ activateRepository( currentRepository );
this.repositoryGroups.put( id, currentRepository );
setLastState( currentRepository, RepositoryState.REGISTERED );
}
}
updateReferences( oldRepository, oldCfg );
setLastState( oldRepository, RepositoryState.REFERENCES_SET );
- initialize( oldRepository );
+ activateRepository( oldRepository );
repositoryGroups.put( id, oldRepository );
setLastState( oldRepository, RepositoryState.REGISTERED );
} else {
this.managedRepositories.putAll( newInstancesFromConfig( ) );
for ( ManagedRepository managedRepository : this.managedRepositories.values( ) )
{
- initialize( managedRepository );
+ activateRepository( managedRepository );
}
}
@Override
- public void initialize( ManagedRepository repository )
+ public void activateRepository( ManagedRepository repository )
{
}
* under the License.
*/
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler;
+import org.apache.archiva.repository.Repository;
+import org.apache.archiva.repository.RepositoryRegistry;
+import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
+import org.apache.archiva.repository.base.ConfigurationHandler;
+import org.apache.archiva.repository.validation.RepositoryValidator;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author Martin Stockhammer <martin_s@apache.org>
*/
+@ExtendWith( SpringExtension.class)
+@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-group.xml" })
class RepositoryGroupHandlerTest
{
+ @Inject
+ @Named("repositoryRegistry")
+ ArchivaRepositoryRegistry repositoryRegistry;
+
+ @Inject
+ ConfigurationHandler configurationHandler;
+
+ @Inject
+ @Named( "mergedRemoteIndexesScheduler#default" )
+ MergedRemoteIndexesScheduler mergedRemoteIndexesScheduler;
+
+ @Inject
+ List<RepositoryValidator<? extends Repository>> repositoryValidatorList;
+
+ @Inject
+ ArchivaConfiguration archivaConfiguration;
+
+
+ private RepositoryGroupHandler createHandler() {
+ RepositoryGroupHandler groupHandler = new RepositoryGroupHandler( repositoryRegistry, configurationHandler, mergedRemoteIndexesScheduler, repositoryValidatorList );
+ groupHandler.init();
+ return groupHandler;
+ }
@Test
void initializeFromConfig( )
{
+ RepositoryGroupHandler groupHandler = createHandler( );
+ assertNotNull( groupHandler );
+ groupHandler.initializeFromConfig();
+ assertEquals( 1, groupHandler.getAll( ).size( ) );
+ assertNotNull( groupHandler.get( "test-group-01" ).getRepositories( ) );
+ assertEquals( "internal", groupHandler.get( "test-group-01" ).getRepositories( ).get( 0 ).getId() );
}
@Test
import org.apache.archiva.event.EventHandler;
import org.apache.archiva.repository.*;
import org.apache.archiva.event.Event;
+import org.apache.archiva.repository.base.group.BasicRepositoryGroup;
import org.apache.archiva.repository.event.RepositoryEvent;
import org.apache.archiva.repository.features.ArtifactCleanupFeature;
import org.apache.archiva.repository.features.IndexCreationFeature;
@Override
public EditableRepositoryGroup createRepositoryGroup(String id, String name) {
- return null;
+ try
+ {
+ return BasicRepositoryGroup.newFilesystemInstance( id, name, Paths.get( "target/groups" ) );
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( );
+ }
+
}
@Override
@Override
public RepositoryGroup createRepositoryGroup(RepositoryGroupConfiguration configuration) throws RepositoryException {
- return null;
+ EditableRepositoryGroup group = createRepositoryGroup( configuration.getId( ), configuration.getName( ) );
+ updateGroupInstance( group, configuration );
+ return group;
+ }
+
+ private void updateGroupInstance( EditableRepositoryGroup group, RepositoryGroupConfiguration configuration )
+ {
+ group.setMergedIndexTTL( configuration.getMergedIndexTtl() );
+ group.setSchedulingDefinition( configuration.getCronExpression() );
}
@Override
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<configuration>
+ <version>3.0.0</version>
+ <managedRepositories>
+ <managedRepository>
+ <id>internal</id>
+ <name>Archiva Managed Internal Repository</name>
+ <description>This is internal repository.</description>
+ <location>${appserver.base}/repositories/internal</location>
+ <indexDir>${appserver.base}/repositories/internal/.indexer</indexDir>
+ <layout>default</layout>
+ <releases>true</releases>
+ <snapshots>false</snapshots>
+ <blockRedeployments>true</blockRedeployments>
+ <scanned>true</scanned>
+ <refreshCronExpression>0 0 * * * ?</refreshCronExpression>
+ <retentionPeriod>30</retentionPeriod>
+ </managedRepository>
+ <managedRepository>
+ <id>staging</id>
+ <name>Repository with staging</name>
+ <description>This is repository with staging.</description>
+ <location>${appserver.base}/repositories/internal</location>
+ <indexDir>${appserver.base}/repositories/internal/.indexer</indexDir>
+ <layout>default</layout>
+ <releases>true</releases>
+ <snapshots>false</snapshots>
+ <blockRedeployments>true</blockRedeployments>
+ <scanned>true</scanned>
+ <refreshCronExpression>0 0 * * * ?</refreshCronExpression>
+ <retentionPeriod>30</retentionPeriod>
+ <stageRepoNeeded>true</stageRepoNeeded>
+ </managedRepository>
+ <managedRepository>
+ <id>snapshots</id>
+ <name>Archiva Managed Snapshot Repository</name>
+ <location>${appserver.base}/repositories/snapshots</location>
+ <indexDir>${appserver.base}/repositories/snapshots/.indexer</indexDir>
+ <layout>default</layout>
+ <releases>false</releases>
+ <snapshots>true</snapshots>
+ <blockRedeployments>false</blockRedeployments>
+ <scanned>true</scanned>
+ <refreshCronExpression>0 0\,30 * * * ?</refreshCronExpression>
+ <retentionPeriod>30</retentionPeriod>
+ </managedRepository>
+ </managedRepositories>
+ <remoteRepositories>
+ <remoteRepository>
+ <id>central</id>
+ <name>Central Repository</name>
+ <url>https://repo.maven.apache.org/maven2</url>
+ <layout>default</layout>
+ <timeout>35</timeout>
+ </remoteRepository>
+ </remoteRepositories>
+ <repositoryGroups>
+ <repositoryGroup>
+ <id>test-group-01</id>
+ <name>Test Group 01</name>
+ <type>MAVEN</type>
+ <repositories>
+ <repository>internal</repository>
+ </repositories>
+ </repositoryGroup>
+ </repositoryGroups>
+
+ <proxyConnectors>
+ <proxyConnector>
+ <sourceRepoId>internal</sourceRepoId>
+ <targetRepoId>central</targetRepoId>
+ <proxyId/>
+ <policies>
+ <snapshots>disabled</snapshots>
+ <releases>once</releases>
+ <checksum>fix</checksum>
+ <cache-failures>cached</cache-failures>
+ </policies>
+ <whiteListPatterns>
+ <whiteListPattern>**/*</whiteListPattern>
+ </whiteListPatterns>
+ </proxyConnector>
+ </proxyConnectors>
+
+ <legacyArtifactPaths>
+ <legacyArtifactPath>
+ <path>jaxen/jars/jaxen-1.0-FCS-full.jar</path>
+ <artifact>jaxen:jaxen:1.0-FCS:full:jar</artifact>
+ </legacyArtifactPath>
+ </legacyArtifactPaths>
+
+ <repositoryScanning>
+ <fileTypes>
+ <fileType>
+ <id>artifacts</id>
+ <patterns>
+ <pattern>**/*.pom</pattern>
+ <pattern>**/*.jar</pattern>
+ <pattern>**/*.ear</pattern>
+ <pattern>**/*.war</pattern>
+ <pattern>**/*.car</pattern>
+ <pattern>**/*.sar</pattern>
+ <pattern>**/*.mar</pattern>
+ <pattern>**/*.rar</pattern>
+ <pattern>**/*.dtd</pattern>
+ <pattern>**/*.tld</pattern>
+ <pattern>**/*.tar.gz</pattern>
+ <pattern>**/*.tar.bz2</pattern>
+ <pattern>**/*.zip</pattern>
+ </patterns>
+ </fileType>
+ <fileType>
+ <id>indexable-content</id>
+ <patterns>
+ <pattern>**/*.txt</pattern>
+ <pattern>**/*.TXT</pattern>
+ <pattern>**/*.block</pattern>
+ <pattern>**/*.config</pattern>
+ <pattern>**/*.pom</pattern>
+ <pattern>**/*.xml</pattern>
+ <pattern>**/*.xsd</pattern>
+ <pattern>**/*.dtd</pattern>
+ <pattern>**/*.tld</pattern>
+ </patterns>
+ </fileType>
+ <fileType>
+ <id>auto-remove</id>
+ <patterns>
+ <pattern>**/*.bak</pattern>
+ <pattern>**/*~</pattern>
+ <pattern>**/*-</pattern>
+ </patterns>
+ </fileType>
+ <fileType>
+ <id>ignored</id>
+ <patterns>
+ <pattern>**/.htaccess</pattern>
+ <pattern>**/KEYS</pattern>
+ <pattern>**/*.rb</pattern>
+ <pattern>**/*.sh</pattern>
+ <pattern>**/.svn/**</pattern>
+ <pattern>**/.DAV/**</pattern>
+ <pattern>.index/**</pattern>
+ <pattern>.indexer/**</pattern>
+ </patterns>
+ </fileType>
+ </fileTypes>
+ <knownContentConsumers>
+ <knownContentConsumer>create-missing-checksums</knownContentConsumer>
+ <knownContentConsumer>validate-checksum</knownContentConsumer>
+ <knownContentConsumer>validate-signature</knownContentConsumer>
+ <knownContentConsumer>index-content</knownContentConsumer>
+ <knownContentConsumer>auto-remove</knownContentConsumer>
+ <knownContentConsumer>auto-rename</knownContentConsumer>
+ <knownContentConsumer>metadata-updater</knownContentConsumer>
+ <knownContentConsumer>create-archiva-metadata</knownContentConsumer>
+ <knownContentConsumer>duplicate-artifacts</knownContentConsumer>
+ <!--knownContentConsumer>repository-purge</knownContentConsumer-->
+ </knownContentConsumers>
+ <invalidContentConsumers>
+ <invalidContentConsumer>update-db-bad-content</invalidContentConsumer>
+ </invalidContentConsumers>
+ </repositoryScanning>
+
+ <webapp>
+ <ui>
+ <showFindArtifacts>true</showFindArtifacts>
+ <appletFindEnabled>true</appletFindEnabled>
+ </ui>
+ </webapp>
+
+ <redbackRuntimeConfiguration>
+ <userManagerImpls>
+ <userManagerImpl>jpa</userManagerImpl>
+ </userManagerImpls>
+ <rbacManagerImpls>
+ <rbacManagerImpl>cached</rbacManagerImpl>
+ </rbacManagerImpls>
+ </redbackRuntimeConfiguration>
+
+ <archivaDefaultConfiguration>
+ <defaultCheckPaths>
+ <defaultCheckPath>
+ <url>http://download.oracle.com/maven</url>
+ <path>com/sleepycat/je/license.txt</path>
+ </defaultCheckPath>
+ <defaultCheckPath>
+ <url>https://download.oracle.com/maven</url>
+ <path>com/sleepycat/je/license.txt</path>
+ </defaultCheckPath>
+ </defaultCheckPaths>
+ </archivaDefaultConfiguration>
+
+</configuration>
--- /dev/null
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context.xsd"
+ default-lazy-init="true">
+
+ <context:annotation-config/>
+ <context:component-scan base-package="org.apache.archiva.repository.mock"/>
+
+
+ <bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="initialConfiguration">
+ <value>
+ <![CDATA[
+ <configuration>
+ <system/>
+ <xml fileName="archiva-group.xml" config-forceCreate="true"
+ config-optional="true"
+ config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+
+ <bean name="taskScheduler#mergeRemoteIndexes"
+ class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
+ <property name="poolSize" value="4"/>
+ <property name="threadGroupName" value="mergeRemoteIndexes"/>
+ </bean>
+
+
+</beans>
\ No newline at end of file