Adapting to component registry changes. Updating to commons configuration 2.

This commit is contained in:
Martin Stockhammer 2019-12-12 18:34:11 +01:00
parent fce356b593
commit af5745356b
31 changed files with 95 additions and 102 deletions

View File

@ -76,8 +76,8 @@
<artifactId>archiva-components-expression-evaluator</artifactId>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<exclusions>
<exclusion>
<groupId>commons-beanutils</groupId>
@ -145,8 +145,12 @@
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-test-utils</artifactId>

View File

@ -35,7 +35,6 @@ import org.apache.archiva.components.registry.RegistryListener;
import org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@ -522,7 +521,7 @@ public class DefaultArchivaConfiguration
contents = "<configuration><xml fileName=\"" + fileLocation
+ "\" config-forceCreate=\"true\" config-name=\"org.apache.archiva.user\"/>" + "</configuration>";
((CommonsConfigurationRegistry) registry).setProperties(contents);
((CommonsConfigurationRegistry) registry).setInitialConfiguration(contents);
registry.initialize();
@ -533,7 +532,11 @@ public class DefaultArchivaConfiguration
triggerEvent(ConfigurationEvent.SAVED);
Registry section = registry.getSection(KEY + ".user");
return section == null ? new CommonsConfigurationRegistry(new BaseConfiguration()) : section;
if (section == null) {
return new CommonsConfigurationRegistry( );
} else {
return section;
}
}
private boolean writeFile(String filetype, String path, String contents) {
@ -796,9 +799,9 @@ public class DefaultArchivaConfiguration
@Override
public synchronized void afterConfigurationChange(Registry registry, String propertyName, Object propertyValue) {
configuration = null;
this.dataDirectory = null;
this.repositoryBaseDirectory = null;
// configuration = null;
// this.dataDirectory = null;
// this.repositoryBaseDirectory = null;
}
private String removeExpressions(String directory) {

View File

@ -30,7 +30,6 @@ import org.apache.archiva.components.registry.commons.CommonsConfigurationRegist
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.IterableUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.configuration.CombinedConfiguration;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
@ -169,48 +168,7 @@ public class FileTypes
@PostConstruct
public void initialize()
{
// TODO: why is this done by hand?
// TODO: ideally, this would be instantiated by configuration instead, and not need to be a component
String errMsg = "Unable to load default archiva configuration for FileTypes: ";
try
{
CommonsConfigurationRegistry commonsRegistry = new CommonsConfigurationRegistry();
// Configure commonsRegistry
Field fld = commonsRegistry.getClass().getDeclaredField( "configuration" );
fld.setAccessible( true );
fld.set( commonsRegistry, new CombinedConfiguration() );
commonsRegistry.addConfigurationFromResource( "org/apache/archiva/configuration/default-archiva.xml" );
// Read configuration as it was intended.
ConfigurationRegistryReader configReader = new ConfigurationRegistryReader();
Configuration defaultConfig = configReader.read( commonsRegistry );
initialiseTypeMap( defaultConfig );
}
catch ( RegistryException e )
{
throw new RuntimeException( errMsg + e.getMessage(), e );
}
catch ( SecurityException e )
{
throw new RuntimeException( errMsg + e.getMessage(), e );
}
catch ( NoSuchFieldException e )
{
throw new RuntimeException( errMsg + e.getMessage(), e );
}
catch ( IllegalArgumentException e )
{
throw new RuntimeException( errMsg + e.getMessage(), e );
}
catch ( IllegalAccessException e )
{
throw new RuntimeException( errMsg + e.getMessage(), e );
}
initialiseTypeMap( this.archivaConfiguration.getConfiguration() );
this.archivaConfiguration.addChangeListener( this );
}

View File

@ -46,7 +46,7 @@
<bean name="registry#test-upgrade-09" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -63,7 +63,7 @@
</bean>
<bean name="registry#test-upgrade-1.3" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -80,7 +80,7 @@
</bean>
<bean name="registry#configured" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -99,7 +99,7 @@
</bean>
<bean name="registry#test-autodetect-v1" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -118,7 +118,7 @@
</bean>
<bean name="registry#test-archiva-v1" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -136,7 +136,7 @@
</bean>
<bean name="registry#test-save" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -153,7 +153,7 @@
</bean>
<bean name="registry#test-save-user-defaults" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -172,7 +172,7 @@
</bean>
<bean name="registry#test-save-user-fallback" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -191,7 +191,7 @@
</bean>
<bean name="registry#test-save-user" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -211,7 +211,7 @@
</bean>
<bean name="registry#test-configuration-both" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -231,7 +231,7 @@
</bean>
<bean name="registry#test-read-saved" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -250,7 +250,7 @@
</bean>
<bean name="registry#test-cron-expressions" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -268,7 +268,7 @@
</bean>
<bean name="registry#test-remove-central" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -288,7 +288,7 @@
</bean>
<bean name="registry#test-not-allowed-to-write-to-both" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -309,7 +309,7 @@
</bean>
<bean name="registry#test-not-allowed-to-write-to-user" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -36,7 +36,7 @@
</bean>
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -38,7 +38,7 @@
<bean name="registry#cleanup-released-snapshots" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -55,7 +55,7 @@
</bean>
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -50,7 +50,7 @@
</bean>
<bean name="registry#retention-count" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -84,7 +84,7 @@
</bean>
<bean name="registry#days-old" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -101,7 +101,7 @@
</bean>
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -30,7 +30,7 @@
<context:component-scan base-package="org.apache.archiva.metadata.repository"/>
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -31,7 +31,7 @@
<context:component-scan base-package="org.apache.archiva.consumers.lucene.test,org.apache.maven.index"/>
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -46,7 +46,7 @@
</bean>
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -25,6 +25,8 @@ import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.common.utils.VersionComparator;
import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.ConfigurationEvent;
import org.apache.archiva.configuration.ConfigurationListener;
import org.apache.archiva.configuration.ConfigurationNames;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
@ -71,7 +73,7 @@ import java.util.stream.Stream;
*/
@Service( "metadataTools#default" )
public class MetadataTools
implements RegistryListener
implements RegistryListener, ConfigurationListener
{
private Logger log = LoggerFactory.getLogger( getClass() );
@ -351,6 +353,7 @@ public class MetadataTools
initConfigVariables();
configuration.addChangeListener( this );
configuration.addListener( this );
}
public ArchivaRepositoryMetadata readProxyMetadata( ManagedRepositoryContent managedRepository,
@ -979,4 +982,10 @@ public class MetadataTools
{
this.filetypes = filetypes;
}
@Override
public void configurationEvent( ConfigurationEvent event )
{
log.debug( "Configuration event {}", event );
}
}

View File

@ -32,7 +32,7 @@
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -33,7 +33,7 @@
</bean>
<bean name="registry#configured" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -39,6 +39,8 @@ import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.repository.Repository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
@ -59,6 +61,8 @@ import java.util.concurrent.ConcurrentMap;
@Service( "repositoryProxyHandler#maven" )
public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
private static final Logger log = LoggerFactory.getLogger( MavenRepositoryProxyHandler.class );
private static final List<RepositoryType> REPOSITORY_TYPES = new ArrayList<>();
static {

View File

@ -26,12 +26,15 @@ import org.apache.archiva.configuration.ConfigurationListener;
import org.apache.archiva.components.registry.Registry;
import org.apache.archiva.components.registry.RegistryException;
import org.apache.archiva.components.registry.RegistryListener;
import org.apache.archiva.configuration.FileType;
import org.apache.archiva.configuration.RepositoryScanningConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.easymock.IMocksControl;
import org.springframework.stereotype.Service;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
@ -66,6 +69,19 @@ public class MockConfiguration
configuration.getArchivaRuntimeConfiguration().addChecksumType("sha1");
configuration.getArchivaRuntimeConfiguration().addChecksumType("sha256");
configuration.getArchivaRuntimeConfiguration().addChecksumType("md5");
RepositoryScanningConfiguration rpsc = new RepositoryScanningConfiguration( );
FileType ft = new FileType( );
ft.setId( "artifacts" );
ArrayList<String> plist = new ArrayList<>( );
plist.add( "**/*.jar" );
plist.add( "**/*.pom" );
plist.add( "**/*.war" );
ft.setPatterns( plist );
rpsc.addFileType( ft );
ArrayList<FileType> ftList = new ArrayList<>( );
ftList.add( ft );
rpsc.setFileTypes( ftList );
configuration.setRepositoryScanning( rpsc );
}
@Override

View File

@ -36,7 +36,7 @@
<alias name="archivaConfiguration#repo-request-test" alias="archivaConfiguration"/>
<bean name="registry#configured" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -48,7 +48,7 @@
<alias name="archivaConfiguration#default" alias="archivaConfiguration"/>
<bean name="registry#default" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -56,7 +56,7 @@
</bean>
<bean name="registry#test-configured" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -54,7 +54,7 @@
<alias name="archivaConfiguration#default" alias="archivaConfiguration"/>
<bean name="registry#default" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>
@ -88,7 +88,7 @@
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"
init-method="initialize">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -87,7 +87,7 @@
<alias name="commons-configuration" alias="registry#test"/>
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -31,7 +31,7 @@
<context:property-placeholder system-properties-mode="OVERRIDE"/>
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -32,7 +32,7 @@
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -56,7 +56,7 @@
</bean>
<bean name="registry#default" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -51,7 +51,7 @@
<alias name="archivaConfiguration#default" alias="archivaConfiguration"/>
<bean name="registry#default" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -53,7 +53,7 @@
<alias name="archivaConfiguration#default" alias="archivaConfiguration"/>
<bean name="registry#default" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -132,8 +132,8 @@
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<exclusions>
<exclusion>
<groupId>commons-beanutils</groupId>

View File

@ -71,7 +71,7 @@
<!-- START SNIPPET: configuration-files-list -->
<bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry"
init-method="initialize">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -38,7 +38,7 @@
<alias name="archivaConfiguration#default" alias="archivaConfiguration"/>
<bean name="registry#default" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -54,7 +54,7 @@
<alias name="archivaConfiguration#default" alias="archivaConfiguration"/>
<bean name="registry#default" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

View File

@ -53,7 +53,7 @@
<alias name="archivaConfiguration#default" alias="archivaConfiguration"/>
<bean name="registry#default" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<property name="initialConfiguration">
<value>
<![CDATA[
<configuration>

11
pom.xml
View File

@ -53,7 +53,6 @@
<commons-fileupload.version>1.4</commons-fileupload.version>
<commons-io.version>2.6</commons-io.version>
<commons-lang.version>3.9</commons-lang.version>
<commons-text.version>1.7</commons-text.version>
<maven3x.version>3.5.4</maven3x.version>
<maven.resolver.version>1.1.1</maven.resolver.version>
@ -690,8 +689,8 @@
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>${commons.configuration.version}</version>
<exclusions>
<exclusion>
@ -731,7 +730,7 @@
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
<version>${commons-beanutils.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
@ -757,12 +756,12 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang.version}</version>
<version>${commons.lang3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
<version>${commons.text.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>