Skip to content
Permalink
Browse files
Refactoring of repository classes
  • Loading branch information
effrafax committed Jul 2, 2021
1 parent 084b9ef commit bf219edd1656cc03dc35d9e4379890d2c2124459
Showing 62 changed files with 784 additions and 122 deletions.
@@ -25,7 +25,7 @@
import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.archiva.consumers.RepositoryContentConsumer;
import org.apache.archiva.repository.base.BasicManagedRepository;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.scanner.RepositoryScanStatistics;
import org.apache.archiva.repository.scanner.RepositoryScanner;
import org.apache.archiva.repository.scanner.RepositoryScannerException;
@@ -36,8 +36,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
@@ -19,6 +19,7 @@
* under the License.
*/

import org.apache.archiva.components.registry.Registry;
import org.apache.archiva.components.registry.RegistryException;
import org.apache.archiva.components.registry.RegistryListener;

@@ -138,5 +139,11 @@ void save( Configuration configuration, String eventTag )
* @return
*/
public Path getDataDirectory();

/**
* Return the used configuration registry
* @return
*/
Registry getRegistry( );
}

@@ -23,9 +23,8 @@
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.event.EventHandler;
import org.apache.archiva.event.EventType;
import org.apache.archiva.repository.base.BasicManagedRepository;
import org.apache.archiva.repository.base.BasicRemoteRepository;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.base.remote.BasicRemoteRepository;
import org.apache.archiva.repository.EditableManagedRepository;
import org.apache.archiva.repository.EditableRemoteRepository;
import org.apache.archiva.repository.RepositoryGroup;
@@ -21,7 +21,7 @@

import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.repository.base.BasicManagedRepository;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryRegistry;
import org.junit.Before;
@@ -4,7 +4,7 @@
import org.apache.archiva.checksum.ChecksummedFile;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.archiva.repository.base.BasicManagedRepository;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.EditableManagedRepository;
import org.apache.commons.io.FileUtils;
import org.assertj.core.api.Assertions;
@@ -24,11 +24,9 @@
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.base.RepositoryGroupHandler;
import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
import org.apache.archiva.repository.maven.metadata.storage.Maven2RepositoryPathTranslator;
import org.apache.archiva.repository.base.BasicManagedRepository;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.RepositoryContentProvider;
import org.apache.archiva.metadata.audit.RepositoryListener;
@@ -43,7 +41,6 @@
import org.junit.runner.RunWith;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;

import javax.inject.Inject;
@@ -23,8 +23,8 @@
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.event.EventHandler;
import org.apache.archiva.repository.base.BasicManagedRepository;
import org.apache.archiva.repository.base.BasicRemoteRepository;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.base.remote.BasicRemoteRepository;
import org.apache.archiva.repository.EditableManagedRepository;
import org.apache.archiva.repository.EditableRemoteRepository;
import org.apache.archiva.repository.EditableRepositoryGroup;
@@ -25,9 +25,9 @@
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.components.taskqueue.TaskQueueException;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.base.BasicManagedRepository;
import org.apache.archiva.repository.base.managed.BasicManagedRepository;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.base.RepositoryGroupHandler;
import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
@@ -31,11 +31,10 @@
import org.apache.archiva.redback.role.RoleManager;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.memory.SimpleUser;
import org.apache.archiva.repository.base.RepositoryGroupHandler;
import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -26,7 +26,7 @@
import org.apache.archiva.metadata.model.facets.AuditEvent;
import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.base.RepositoryGroupHandler;
import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
import org.junit.Test;

import javax.inject.Inject;
@@ -18,8 +18,10 @@
*/

import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.repository.validation.CheckedResult;
import org.apache.archiva.repository.validation.RepositoryChecker;
import org.apache.archiva.repository.validation.RepositoryValidator;
import org.apache.archiva.repository.validation.ValidationResponse;

import java.util.Collection;
import java.util.Map;
@@ -165,6 +167,28 @@
*/
RepositoryValidator<R> getValidator( );

/**
* Validates the set attributes of the given repository instance and returns the validation result.
* The repository registry uses all available validators and applies their validateRepository method to the given
* repository. Validation results will be merged per field.
*
* @param repository the repository to validate against
* @return the result of the validation.
*/
ValidationResponse<R> validateRepository( R repository);

/**
* Validates the set attributes of the given repository instance for a repository update and returns the validation result.
* The repository registry uses all available validators and applies their validateRepositoryForUpdate method to the given
* repository. Validation results will be merged per field.
*
* @param repository the repository to validate against
* @return the result of the validation.
*/
ValidationResponse<R> validateRepositoryForUpdate( R repository);



/**
* Returns <code>true</code>, if the repository is registered with the given id, otherwise <code>false</code>
* @param id the repository identifier
@@ -29,6 +29,7 @@
import org.apache.archiva.indexer.IndexUpdateFailedException;
import org.apache.archiva.repository.metadata.MetadataReader;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.repository.validation.CheckedResult;
import org.apache.archiva.repository.validation.ValidationError;
import org.apache.archiva.repository.validation.ValidationResponse;

@@ -17,23 +17,50 @@
* under the License.
*/

import org.apache.archiva.repository.CheckedResult;
import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.RepositoryRegistry;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Martin Stockhammer <martin_s@apache.org>
*/
public abstract class AbstractRepositoryValidator<R extends Repository> implements RepositoryValidator<R>
{
protected RepositoryRegistry repositoryRegistry;
private final String category;

public AbstractRepositoryValidator( String category )
{
this.category = category;
}

@Override
public void setRepositoryRegistry( RepositoryRegistry repositoryRegistry )
{
this.repositoryRegistry = repositoryRegistry;
}

protected String getCategory() {
return this.category;
}



protected Map<String, List<ValidationError>> appendError( Map<String, List<ValidationError>> errorMap, String attribute, String type, Object... parameter )
{
String errorKey = getCategory( ) + "." + attribute + "." + type;
Map<String, List<ValidationError>> result;
result = errorMap == null ? new HashMap<>( ) : errorMap;
ValidationError error = ValidationError.ofKey( errorKey, parameter );
List<ValidationError> errList = result.computeIfAbsent( error.getAttribute( ), k -> new ArrayList<>( ) );
errList.add( error );
return result;
}

protected abstract ValidationResponse<R> apply( R repo, boolean update );

@Override
@@ -1,4 +1,4 @@
package org.apache.archiva.repository;
package org.apache.archiva.repository.validation;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -17,6 +17,8 @@
* under the License.
*/

import org.apache.archiva.repository.Repository;

/**
* @author Martin Stockhammer <martin_s@apache.org>
*/
@@ -0,0 +1,74 @@
package org.apache.archiva.repository.validation;
/*
* 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.repository.Repository;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Martin Stockhammer <martin_s@apache.org>
*/
public class CombinedValidationResponse<R extends Repository> implements CheckedResult<R, Map<String, List<ValidationError>>>
{

private final Map<String, List<ValidationError>> errorMap = new HashMap<>( );
private final R repository;

public CombinedValidationResponse( R repository )
{
this.repository = repository;
}

@Override
public R getRepository( )
{
return repository;
}

@Override
public boolean isValid( )
{
return errorMap.size()==0;
}

@Override
public Map<String, List<ValidationError>> getResult( )
{
return errorMap;
}

public void addErrors(String key, List<ValidationError> errorList) {
if ( StringUtils.isNotEmpty( key ) && errorList!=null && errorList.size()>0) {
this.errorMap.put( key, errorList );
}
}

public void addErrors(Map<String, List<ValidationError>> errorMap) {
if (errorMap!=null) {
errorMap.entrySet( ).stream( ).forEach( e -> addErrors( e.getKey( ), e.getValue( ) ) );
}
}

public void addResult(CheckedResult<R, Map<String, List<ValidationError>>> result) {
this.addErrors( result.getResult( ) );
}
}

0 comments on commit bf219ed

Please sign in to comment.