Skip to content
Permalink
Browse files
Additional tests and refactoring
  • Loading branch information
effrafax committed Jul 4, 2021
1 parent bc27b25 commit 11d469489e533a0e038b0a44e732595efcd082ed
Showing 19 changed files with 1,002 additions and 139 deletions.
@@ -695,15 +695,9 @@ public java.util.Map<String, RepositoryGroupConfiguration> getRepositoryGroupsAs

public RepositoryGroupConfiguration findRepositoryGroupById( String id )
{
if ( repositoryGroups != null )
if ( repositoryGroups != null && id!=null)
{
for ( RepositoryGroupConfiguration group : (java.util.List<RepositoryGroupConfiguration>) repositoryGroups )
{
if ( group.getId().equals( id ) )
{
return group;
}
}
return ( (java.util.List<RepositoryGroupConfiguration>) repositoryGroups ).stream( ).filter( g -> g != null && id.equals( g.getId( ) ) ).findFirst( ).orElse( null );
}
return null;
}
@@ -21,36 +21,49 @@
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.ValidationError;
import org.apache.archiva.repository.validation.ValidationResponse;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
*
* This is the generic interface that handles different repository flavours.
* This is the generic interface that handles different repository flavours, currently for
* ManagedRepository, RemoteRepository and RepositoryGroup
*
* @author Martin Stockhammer <martin_s@apache.org>
*/
public interface RepositoryHandler<R extends Repository, C>
{

/**
* Creates instances from the archiva configuration. The instances are not registered in the registry.
* Initializes the current state from the configuration
*/
void initializeFromConfig( );

/**
* Initializes the repository. E.g. starts scheduling and activate additional processes.
* @param repository the repository to initialize
*/
void initialize( R repository );

/**
* Creates new instances from the archiva configuration. The instances are not registered in the registry.
*
* @return A map of (repository id, Repository) pairs
*/
Map<String, R> newInstancesFromConfig();
Map<String, R> newInstancesFromConfig( );

/**
* Creates a new instance without registering and without updating the archiva configuration
*
* @param type the repository type
* @param id the repository identifier
* @param id the repository identifier
* @return the repository instance
* @throws RepositoryException if the creation failed
*/
R newInstance(RepositoryType type, String id) throws RepositoryException;
R newInstance( RepositoryType type, String id ) throws RepositoryException;

/**
* Creates a new instance and updates the given configuration object.
@@ -90,7 +103,7 @@
* and not initialized. References are not updated.
*
* @param repositoryConfiguration the repository configuration
* @param configuration the configuration instance
* @param configuration the configuration instance
* @return the repository instance that was created or updated
* @throws RepositoryException if the update or creation failed
*/
@@ -102,12 +115,12 @@
* If the checker returns a valid result, the registry is updated and configuration is saved.
*
* @param repositoryConfiguration the repository configuration
* @param checker the checker that validates the repository data
* @param checker the checker that validates the repository data
* @return the repository and the check result
* @throws RepositoryException if the creation or update failed
*/
<D> CheckedResult<R, D>
putWithCheck( C repositoryConfiguration, RepositoryChecker<R, D> checker) throws RepositoryException;
putWithCheck( C repositoryConfiguration, RepositoryChecker<R, D> checker ) throws RepositoryException;

/**
* Removes the given repository from the registry and updates references and saves the new configuration.
@@ -121,7 +134,7 @@
* Removes the given repository from the registry and updates only the given configuration instance.
* The archiva registry is not updated
*
* @param id the repository identifier
* @param id the repository identifier
* @param configuration the configuration to update
* @throws RepositoryException if the repository could not be removed
*/
@@ -141,15 +154,15 @@
* @param repo the repository that should be cloned
* @return a newly created instance with the same repository data
*/
R clone(R repo) throws RepositoryException;
R clone( R repo ) throws RepositoryException;

/**
* Updates the references and stores updates in the given <code>configuration</code> instance.
* The references that are updated depend on the concrete repository subclass <code>R</code>.
* This method may register/unregister repositories depending on the implementation. That means there is no simple
* way to roll back, if an error occurs.
*
* @param repo the repository for which references are updated
* @param repo the repository for which references are updated
* @param repositoryConfiguration the repository configuration
*/
void updateReferences( R repo, C repositoryConfiguration ) throws RepositoryException;
@@ -159,10 +172,11 @@
*
* @return the list of repositories
*/
Collection<R> getAll();
Collection<R> getAll( );

/**
* Returns a validator that can be used to validate repository data
*
* @return a validator instance
*/
RepositoryValidator<R> getValidator( );
@@ -175,7 +189,7 @@
* @param repository the repository to validate against
* @return the result of the validation.
*/
ValidationResponse<R> validateRepository( R repository);
CheckedResult<R,Map<String, List<ValidationError>>> validateRepository( R repository );

/**
* Validates the set attributes of the given repository instance for a repository update and returns the validation result.
@@ -185,25 +199,25 @@
* @param repository the repository to validate against
* @return the result of the validation.
*/
ValidationResponse<R> validateRepositoryForUpdate( R repository);

CheckedResult<R,Map<String, List<ValidationError>>> 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
* @return <code>true</code>, if it is registered, otherwise <code>false</code>
*/
boolean has(String id);
boolean has( String id );

/**
* Initializes
*/
void init();
void init( );

/**
* Closes the handler
*/
void close();
void close( );

}
@@ -34,7 +34,10 @@ public class AbstractFeature {
}

AbstractFeature(EventHandler listener) {
this.listener.add(listener);
if (listener!=null)
{
this.listener.add( listener );
}
}

AbstractFeature(Collection<EventHandler> listeners) {
@@ -173,7 +173,7 @@ public URI getPackedIndexPath() {
/**
* Sets the path (relative or absolute) of the packed index.
*
* Throws a {@link RepositoryIndexEvent.Index#PACKED_INDEX_URI_CHANGE}, if the value changes.
* Throws a {@link RepositoryIndexEvent#packedIndexUriChange(Object, Repository, URI, URI)}, if the value changes.
*
* @param packedIndexPath the new path uri for the packed index
*/
@@ -33,6 +33,6 @@
String MAX_LENGTH_EXCEEDED = "max_length";
String INVALID_CHARS = "invalid_chars";
String BELOW_MIN = "min";
String INVALID_SCHEDULING_EXPRESSION = "scheduling_exp_invalid";
String INVALID_LOCATION = "location_invalid";
String INVALID_SCHEDULING_EXPRESSION = "invalid_scheduling_exp";
String INVALID_LOCATION = "invalid_location";
}
@@ -34,7 +34,9 @@
{

String REPOSITORY_ID_VALID_EXPRESSION = "^[a-zA-Z0-9._-]+$";
String[] REPOSITORY_ID_ALLOWED = new String[]{"alphanumeric, '.', '-','_'"};
String REPOSITORY_NAME_VALID_EXPRESSION = "^([a-zA-Z0-9.)/_(-]|\\s)+$";
String[] REPOSITORY_NAME_ALLOWED = new String[]{"alphanumeric", "whitespace", "/", "(", ")", "_", ".", "-"};
String REPOSITORY_LOCATION_VALID_EXPRESSION = "^[-a-zA-Z0-9._/~:?!&amp;=\\\\]+$";


@@ -287,11 +287,6 @@ public void setBaseUri(URI baseUri) {

@Override
public void setSchedulingDefinition(String cronExpression) {
if (StringUtils.isNotEmpty( cronExpression ))
{
CronParser parser = new CronParser( CRON_DEFINITION );
parser.parse( cronExpression ).validate( );
}
this.schedulingDefinition = cronExpression;
}

@@ -302,9 +297,6 @@ protected <T extends RepositoryFeature<T>> void addFeature(RepositoryFeature<T>

@Override
public void setIndexingContext(ArchivaIndexingContext context) {
if (this.indexingContext!=null) {

}
this.indexingContext = context;
}

@@ -0,0 +1,49 @@
package org.apache.archiva.repository.base;
/*
* 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.archiva.repository.RepositoryHandler;
import org.apache.archiva.repository.validation.CombinedValidator;
import org.apache.archiva.repository.validation.RepositoryValidator;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* Base abstract class for repository handlers.
* @author Martin Stockhammer <martin_s@apache.org>
*/
public abstract class AbstractRepositoryHandler<R extends Repository, C> implements RepositoryHandler<R, C>
{
protected List<RepositoryValidator<R>> initValidators( Class<R> clazz, List<RepositoryValidator<? extends Repository>> repositoryGroupValidatorList) {
if (repositoryGroupValidatorList!=null && repositoryGroupValidatorList.size()>0) {
return repositoryGroupValidatorList.stream( ).filter(
v -> v.isFlavour( clazz )
).map( v -> v.narrowTo( clazz ) ).collect( Collectors.toList( ) );
} else {
return Collections.emptyList( );
}
}

protected CombinedValidator<R> getCombinedValidatdor(Class<R> clazz, List<RepositoryValidator<? extends Repository>> repositoryGroupValidatorList) {
return new CombinedValidator<>( clazz, initValidators( clazz, repositoryGroupValidatorList ) );
}

}

0 comments on commit 11d4694

Please sign in to comment.