1 package org.apache.archiva.configuration;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.configuration.functors.ProxyConnectorConfigurationOrderComparator;
23 import org.apache.archiva.configuration.io.registry.ConfigurationRegistryReader;
24 import org.apache.archiva.configuration.io.registry.ConfigurationRegistryWriter;
25 import org.apache.archiva.policies.AbstractUpdatePolicy;
26 import org.apache.archiva.policies.CachedFailuresPolicy;
27 import org.apache.archiva.policies.ChecksumPolicy;
28 import org.apache.archiva.policies.DownloadErrorPolicy;
29 import org.apache.archiva.policies.Policy;
30 import org.apache.archiva.policies.PostDownloadPolicy;
31 import org.apache.archiva.policies.PreDownloadPolicy;
32 import org.apache.archiva.redback.components.evaluator.DefaultExpressionEvaluator;
33 import org.apache.archiva.redback.components.evaluator.EvaluatorException;
34 import org.apache.archiva.redback.components.evaluator.ExpressionEvaluator;
35 import org.apache.archiva.redback.components.evaluator.sources.SystemPropertyExpressionSource;
36 import org.apache.archiva.redback.components.registry.Registry;
37 import org.apache.archiva.redback.components.registry.RegistryException;
38 import org.apache.archiva.redback.components.registry.RegistryListener;
39 import org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry;
40 import org.apache.archiva.redback.components.springutils.ComponentContainer;
41 import org.apache.commons.collections.CollectionUtils;
42 import org.apache.commons.collections.ListUtils;
43 import org.apache.commons.collections.MapUtils;
44 import org.apache.commons.configuration.BaseConfiguration;
45 import org.apache.commons.io.FileUtils;
46 import org.apache.commons.lang.StringUtils;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49 import org.springframework.stereotype.Service;
51 import javax.annotation.PostConstruct;
52 import javax.inject.Inject;
53 import javax.inject.Named;
54 import java.io.IOException;
55 import java.nio.file.Files;
56 import java.nio.file.Path;
57 import java.nio.file.Paths;
58 import java.util.ArrayList;
59 import java.util.Arrays;
60 import java.util.Collection;
61 import java.util.Collections;
62 import java.util.HashMap;
63 import java.util.HashSet;
64 import java.util.Iterator;
65 import java.util.List;
67 import java.util.Map.Entry;
72 * Implementation of configuration holder that retrieves it from the registry.
75 * The registry layers and merges the 2 configuration files: user, and application server.
78 * Instead of relying on the model defaults, if the registry is empty a default configuration file is loaded and
79 * applied from a resource. The defaults are not loaded into the registry as the lists (eg repositories) could no longer
80 * be removed if that was the case.
83 * When saving the configuration, it is saved to the location it was read from. If it was read from the defaults, it
84 * will be saved to the user location.
85 * However, if the configuration contains information from both sources, an exception is raised as this is currently
86 * unsupported. The reason for this is that it is not possible to identify where to re-save elements, and can result
87 * in list configurations (eg repositories) becoming inconsistent.
90 * If the configuration is outdated, it will be upgraded when it is loaded. This is done by checking the version flag
91 * before reading it from the registry.
94 @Service("archivaConfiguration#default")
95 public class DefaultArchivaConfiguration
96 implements ArchivaConfiguration, RegistryListener
98 private Logger log = LoggerFactory.getLogger( DefaultArchivaConfiguration.class );
100 private static String FILE_ENCODING = "UTF-8";
103 * Plexus registry to read the configuration from.
106 @Named(value = "commons-configuration")
107 private Registry registry;
110 private ComponentContainer componentContainer;
113 * The configuration that has been converted.
115 private Configuration configuration;
120 * @todo these don't strictly belong in here
122 private Map<String, PreDownloadPolicy> prePolicies;
127 * @todo these don't strictly belong in here
129 private Map<String, PostDownloadPolicy> postPolicies;
134 * @todo these don't strictly belong in here
136 private Map<String, DownloadErrorPolicy> downloadErrorPolicies;
141 * default-value="${user.home}/.m2/archiva.xml"
143 private String userConfigFilename = "${user.home}/.m2/archiva.xml";
147 * default-value="${appserver.base}/conf/archiva.xml"
149 private String altConfigFilename = "${appserver.base}/conf/archiva.xml";
152 * Configuration Listeners we've registered.
154 private Set<ConfigurationListener> listeners = new HashSet<>();
157 * Registry Listeners we've registered.
159 private Set<RegistryListener> registryListeners = new HashSet<>();
162 * Boolean to help determine if the configuration exists as a result of pulling in
163 * the default-archiva.xml
165 private boolean isConfigurationDefaulted = false;
167 private static final String KEY = "org.apache.archiva";
169 // Section used for default only configuration
170 private static final String KEY_DEFAULT_ONLY = "org.apache.archiva_default";
173 public Configuration getConfiguration()
175 return loadConfiguration();
178 private synchronized Configuration loadConfiguration()
180 if ( configuration == null )
182 configuration = load();
183 configuration = unescapeExpressions( configuration );
184 if ( isConfigurationDefaulted )
186 configuration = checkRepositoryLocations( configuration );
190 return configuration;
193 private boolean hasConfigVersionChanged(Configuration current, Registry defaultOnlyConfiguration) {
194 return current==null || current.getVersion()==null ||
195 !current.getVersion().trim().equals(defaultOnlyConfiguration.getString("version","").trim());
198 @SuppressWarnings("unchecked")
199 private Configuration load()
201 // TODO: should this be the same as section? make sure unnamed sections still work (eg, sys properties)
202 Registry subset = registry.getSubset( KEY );
203 if ( subset.getString( "version" ) == null )
205 if ( subset.getSubset( "repositoryScanning" ).isEmpty() )
208 subset = readDefaultConfiguration();
211 throw new RuntimeException( "No version tag found in configuration. Archiva configuration version 1.x is not longer supported." );
215 Configuration config = new ConfigurationRegistryReader().read( subset );
216 if (StringUtils.isEmpty( config.getArchivaRuntimeConfiguration().getDataDirectory() )) {
217 Path appserverBaseDir = Paths.get(registry.getString("appserver.base", ""));
218 config.getArchivaRuntimeConfiguration().setDataDirectory( appserverBaseDir.normalize().toString() );
220 if (StringUtils.isEmpty( config.getArchivaRuntimeConfiguration().getRepositoryBaseDirectory())) {
221 Path baseDir = Paths.get(config.getArchivaRuntimeConfiguration().getDataDirectory());
222 config.getArchivaRuntimeConfiguration().setRepositoryBaseDirectory( baseDir.resolve("repositories").toString() );
225 config.getRepositoryGroups();
226 config.getRepositoryGroupsAsMap();
227 if ( !CollectionUtils.isEmpty( config.getRemoteRepositories() ) )
229 List<RemoteRepositoryConfiguration> remoteRepos = config.getRemoteRepositories();
230 for ( RemoteRepositoryConfiguration repo : remoteRepos )
232 // [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
233 if ( StringUtils.isBlank( repo.getUsername() ) )
235 repo.setUsername( null );
238 if ( StringUtils.isBlank( repo.getPassword() ) )
240 repo.setPassword( null );
245 if ( !config.getProxyConnectors().isEmpty() )
247 // Fix Proxy Connector Settings.
249 // Create a copy of the list to read from (to prevent concurrent modification exceptions)
250 List<ProxyConnectorConfiguration> proxyConnectorList = new ArrayList<>( config.getProxyConnectors() );
251 // Remove the old connector list.
252 config.getProxyConnectors().clear();
254 for ( ProxyConnectorConfiguration connector : proxyConnectorList )
257 boolean connectorValid = true;
259 Map<String, String> policies = new HashMap<>();
260 // Make copy of policies
261 policies.putAll( connector.getPolicies() );
262 // Clear out policies
263 connector.getPolicies().clear();
265 // Work thru policies. cleaning them up.
266 for ( Entry<String, String> entry : policies.entrySet() )
268 String policyId = entry.getKey();
269 String setting = entry.getValue();
271 // Upgrade old policy settings.
272 if ( "releases".equals( policyId ) || "snapshots".equals( policyId ) )
274 if ( "ignored".equals( setting ) )
276 setting = AbstractUpdatePolicy.ALWAYS;
278 else if ( "disabled".equals( setting ) )
280 setting = AbstractUpdatePolicy.NEVER;
283 else if ( "cache-failures".equals( policyId ) )
285 if ( "ignored".equals( setting ) )
287 setting = CachedFailuresPolicy.NO;
289 else if ( "cached".equals( setting ) )
291 setting = CachedFailuresPolicy.YES;
294 else if ( "checksum".equals( policyId ) )
296 if ( "ignored".equals( setting ) )
298 setting = ChecksumPolicy.IGNORE;
302 // Validate existance of policy key.
303 if ( policyExists( policyId ) )
305 Policy policy = findPolicy( policyId );
306 // Does option exist?
307 if ( !policy.getOptions().contains( setting ) )
309 setting = policy.getDefaultOption();
311 connector.addPolicy( policyId, setting );
315 // Policy key doesn't exist. Don't add it to golden version.
316 log.warn( "Policy [{}] does not exist.", policyId );
320 if ( connectorValid )
322 config.addProxyConnector( connector );
326 // Normalize the order fields in the proxy connectors.
327 Map<String, java.util.List<ProxyConnectorConfiguration>> proxyConnectorMap =
328 config.getProxyConnectorAsMap();
330 for ( List<ProxyConnectorConfiguration> connectors : proxyConnectorMap.values() )
332 // Sort connectors by order field.
333 Collections.sort( connectors, ProxyConnectorConfigurationOrderComparator.getInstance() );
335 // Normalize the order field values.
337 for ( ProxyConnectorConfiguration connector : connectors )
339 connector.setOrder( order++ );
350 * Updates the checkpath list for repositories.
352 * We are replacing existing ones and adding new ones. This allows to update the list with new releases.
354 * We are also updating existing remote repositories, if they exist already.
356 * This update method should only be called, if the config version changes to avoid overwriting
357 * user repository settings all the time.
359 private void updateCheckPathDefaults(Configuration config, Registry defaultConfiguration) {
360 List<RepositoryCheckPath> existingCheckPathList = config.getArchivaDefaultConfiguration().getDefaultCheckPaths();
361 HashMap<String, RepositoryCheckPath> existingCheckPaths = new HashMap<>();
362 HashMap<String, RepositoryCheckPath> newCheckPaths = new HashMap<>();
363 for (RepositoryCheckPath path : config.getArchivaDefaultConfiguration().getDefaultCheckPaths()) {
364 existingCheckPaths.put(path.getUrl(), path);
366 List defaultCheckPathsSubsets = defaultConfiguration.getSubsetList("archivaDefaultConfiguration.defaultCheckPaths.defaultCheckPath" );
367 for ( Iterator i = defaultCheckPathsSubsets.iterator(); i.hasNext(); )
369 RepositoryCheckPath v = readRepositoryCheckPath( (Registry) i.next() );
370 if (existingCheckPaths.containsKey(v.getUrl())) {
371 existingCheckPathList.remove(existingCheckPaths.get(v.getUrl()));
373 existingCheckPathList.add(v);
374 newCheckPaths.put(v.getUrl(), v);
376 // Remote repositories update
377 for (RemoteRepositoryConfiguration remoteRepositoryConfiguration : config.getRemoteRepositories()) {
378 String url = remoteRepositoryConfiguration.getUrl().toLowerCase();
379 if (newCheckPaths.containsKey(url)) {
380 String currentPath = remoteRepositoryConfiguration.getCheckPath();
381 String newPath = newCheckPaths.get(url).getPath();
382 log.info("Updating connection check path for repository {}, from '{}' to '{}'.", remoteRepositoryConfiguration.getId(),
383 currentPath, newPath);
384 remoteRepositoryConfiguration.setCheckPath(newPath);
389 private RepositoryCheckPath readRepositoryCheckPath( Registry registry )
391 RepositoryCheckPath value = new RepositoryCheckPath();
393 String url = registry.getString( "url", value.getUrl() );
396 String path = registry.getString( "path", value.getPath() );
397 value.setPath( path );
401 private Policy findPolicy( String policyId )
403 if ( MapUtils.isEmpty( prePolicies ) )
405 log.error( "No PreDownloadPolicies found!" );
409 if ( MapUtils.isEmpty( postPolicies ) )
411 log.error( "No PostDownloadPolicies found!" );
417 policy = prePolicies.get( policyId );
418 if ( policy != null )
423 policy = postPolicies.get( policyId );
424 if ( policy != null )
429 policy = downloadErrorPolicies.get( policyId );
430 if ( policy != null )
438 private boolean policyExists( String policyId )
440 if ( MapUtils.isEmpty( prePolicies ) )
442 log.error( "No PreDownloadPolicies found!" );
446 if ( MapUtils.isEmpty( postPolicies ) )
448 log.error( "No PostDownloadPolicies found!" );
452 return ( prePolicies.containsKey( policyId ) || postPolicies.containsKey( policyId )
453 || downloadErrorPolicies.containsKey( policyId ) );
456 private Registry readDefaultConfiguration()
458 // if it contains some old configuration, remove it (Archiva 0.9)
459 registry.removeSubset( KEY );
463 registry.addConfigurationFromResource( "org/apache/archiva/configuration/default-archiva.xml", KEY );
464 this.isConfigurationDefaulted = true;
466 catch ( RegistryException e )
468 throw new ConfigurationRuntimeException(
469 "Fatal error: Unable to find the built-in default configuration and load it into the registry", e );
471 return registry.getSubset( KEY );
475 * Reads the default only configuration into a special prefix. This allows to check for changes
476 * of the default configuration.
478 private Registry readDefaultOnlyConfiguration()
480 registry.removeSubset(KEY_DEFAULT_ONLY);
483 registry.addConfigurationFromResource( "org/apache/archiva/configuration/default-archiva.xml", KEY_DEFAULT_ONLY);
485 catch ( RegistryException e )
487 throw new ConfigurationRuntimeException(
488 "Fatal error: Unable to find the built-in default configuration and load it into the registry", e );
490 return registry.getSubset(KEY_DEFAULT_ONLY);
493 @SuppressWarnings("unchecked")
495 public synchronized void save( Configuration configuration )
496 throws IndeterminateConfigurationException, RegistryException
498 Registry section = registry.getSection( KEY + ".user" );
499 Registry baseSection = registry.getSection( KEY + ".base" );
500 if ( section == null )
502 section = baseSection;
503 if ( section == null )
505 section = createDefaultConfigurationFile();
508 else if ( baseSection != null )
510 Collection<String> keys = baseSection.getKeys();
511 boolean foundList = false;
512 for ( Iterator<String> i = keys.iterator(); i.hasNext() && !foundList; )
514 String key = i.next();
516 // a little aggressive with the repositoryScanning and databaseScanning - should be no need to split
517 // that configuration
518 if ( key.startsWith( "repositories" ) //
519 || key.startsWith( "proxyConnectors" ) //
520 || key.startsWith( "networkProxies" ) //
521 || key.startsWith( "repositoryScanning" ) //
522 || key.startsWith( "remoteRepositories" ) //
523 || key.startsWith( "managedRepositories" ) //
524 || key.startsWith( "repositoryGroups" ) ) //
532 this.configuration = null;
534 throw new IndeterminateConfigurationException(
535 "Configuration can not be saved when it is loaded from two sources" );
539 // escape all cron expressions to handle ','
540 escapeCronExpressions( configuration );
542 // [MRM-661] Due to a bug in the modello registry writer, we need to take these out by hand. They'll be put back by the writer.
543 if ( section != null )
545 if ( configuration.getManagedRepositories().isEmpty() )
547 section.removeSubset( "managedRepositories" );
549 if ( configuration.getRemoteRepositories().isEmpty() )
551 section.removeSubset( "remoteRepositories" );
554 if ( configuration.getProxyConnectors().isEmpty() )
556 section.removeSubset( "proxyConnectors" );
558 if ( configuration.getNetworkProxies().isEmpty() )
560 section.removeSubset( "networkProxies" );
562 if ( configuration.getLegacyArtifactPaths().isEmpty() )
564 section.removeSubset( "legacyArtifactPaths" );
566 if ( configuration.getRepositoryGroups().isEmpty() )
568 section.removeSubset( "repositoryGroups" );
570 if ( configuration.getRepositoryScanning() != null )
572 if ( configuration.getRepositoryScanning().getKnownContentConsumers().isEmpty() )
574 section.removeSubset( "repositoryScanning.knownContentConsumers" );
576 if ( configuration.getRepositoryScanning().getInvalidContentConsumers().isEmpty() )
578 section.removeSubset( "repositoryScanning.invalidContentConsumers" );
581 if (configuration.getArchivaRuntimeConfiguration()!=null) {
582 section.removeSubset("archivaRuntimeConfiguration.defaultCheckPaths");
585 new ConfigurationRegistryWriter().write( configuration, section );
591 this.configuration = unescapeExpressions( configuration );
593 triggerEvent( ConfigurationEvent.SAVED );
596 private void escapeCronExpressions( Configuration configuration )
598 for ( ManagedRepositoryConfiguration c : configuration.getManagedRepositories() )
600 c.setRefreshCronExpression( escapeCronExpression( c.getRefreshCronExpression() ) );
604 private Registry createDefaultConfigurationFile()
605 throws RegistryException
607 // TODO: may not be needed under commons-configuration 1.4 - check
609 String contents = "<configuration />";
611 String fileLocation = userConfigFilename;
613 if ( !writeFile( "user configuration", userConfigFilename, contents ) )
615 fileLocation = altConfigFilename;
616 if ( !writeFile( "alternative configuration", altConfigFilename, contents ) )
618 throw new RegistryException(
619 "Unable to create configuration file in either user [" + userConfigFilename + "] or alternative ["
621 + "] locations on disk, usually happens when not allowed to write to those locations." );
625 // olamy hackish I know :-)
626 contents = "<configuration><xml fileName=\"" + fileLocation
627 + "\" config-forceCreate=\"true\" config-name=\"org.apache.archiva.user\"/>" + "</configuration>";
629 ( (CommonsConfigurationRegistry) registry ).setProperties( contents );
631 registry.initialize();
633 for ( RegistryListener regListener : registryListeners )
635 addRegistryChangeListener( regListener );
638 triggerEvent( ConfigurationEvent.SAVED );
640 Registry section = registry.getSection( KEY + ".user" );
641 return section == null ? new CommonsConfigurationRegistry( new BaseConfiguration() ) : section;
645 * Attempts to write the contents to a file, if an IOException occurs, return false.
647 * The file will be created if the directory to the file exists, otherwise this will return false.
649 * @param filetype the filetype (freeform text) to use in logging messages when failure to write.
650 * @param path the path to write to.
651 * @param contents the contents to write.
652 * @return true if write successful.
654 private boolean writeFile( String filetype, String path, String contents )
656 Path file = Paths.get( path );
660 // Check parent directory (if it is declared)
661 if ( file.getParent() != null )
663 // Check that directory exists
664 if ( !Files.isDirectory( file.getParent() ) )
666 // Directory to file must exist for file to be created
670 FileUtils.writeStringToFile( file.toFile(), contents, FILE_ENCODING);
673 catch ( IOException e )
675 log.error( "Unable to create {} file: {}", filetype, e.getMessage(), e );
680 private void triggerEvent( int type )
682 ConfigurationEvent evt = new ConfigurationEvent( type );
683 for ( ConfigurationListener listener : listeners )
685 listener.configurationEvent( evt );
690 public void addListener( ConfigurationListener listener )
692 if ( listener == null )
697 listeners.add( listener );
701 public void removeListener( ConfigurationListener listener )
703 if ( listener == null )
708 listeners.remove( listener );
713 public void addChangeListener( RegistryListener listener )
715 addRegistryChangeListener( listener );
717 // keep track for later
718 registryListeners.add( listener );
721 private void addRegistryChangeListener( RegistryListener listener )
723 Registry section = registry.getSection( KEY + ".user" );
724 if ( section != null )
726 section.addChangeListener( listener );
728 section = registry.getSection( KEY + ".base" );
729 if ( section != null )
731 section.addChangeListener( listener );
736 public void removeChangeListener( RegistryListener listener )
738 boolean removed = registryListeners.remove( listener );
739 log.debug( "RegistryListener: '{}' removed {}", listener, removed );
741 Registry section = registry.getSection( KEY + ".user" );
742 if ( section != null )
744 section.removeChangeListener( listener );
746 section = registry.getSection( KEY + ".base" );
747 if ( section != null )
749 section.removeChangeListener( listener );
755 public void initialize()
758 this.postPolicies = componentContainer.buildMapWithRole( PostDownloadPolicy.class );
759 this.prePolicies = componentContainer.buildMapWithRole( PreDownloadPolicy.class );
760 this.downloadErrorPolicies = componentContainer.buildMapWithRole( DownloadErrorPolicy.class );
761 // Resolve expressions in the userConfigFilename and altConfigFilename
764 ExpressionEvaluator expressionEvaluator = new DefaultExpressionEvaluator();
765 expressionEvaluator.addExpressionSource( new SystemPropertyExpressionSource() );
766 String userConfigFileNameSysProps = System.getProperty( "archiva.user.configFileName" );
767 if ( StringUtils.isNotBlank( userConfigFileNameSysProps ) )
769 userConfigFilename = userConfigFileNameSysProps;
773 userConfigFilename = expressionEvaluator.expand( userConfigFilename );
775 altConfigFilename = expressionEvaluator.expand( altConfigFilename );
777 handleUpgradeConfiguration();
779 catch ( IndeterminateConfigurationException | RegistryException e )
781 throw new RuntimeException( "failed during upgrade from previous version" + e.getMessage(), e );
783 catch ( EvaluatorException e )
785 throw new RuntimeException(
786 "Unable to evaluate expressions found in " + "userConfigFilename or altConfigFilename.", e );
788 registry.addChangeListener( this );
792 * Handle upgrade to newer version
794 private void handleUpgradeConfiguration()
795 throws RegistryException, IndeterminateConfigurationException
798 List<String> dbConsumers = Arrays.asList( "update-db-artifact", "update-db-repository-metadata" );
800 // remove database consumers if here
801 List<String> intersec =
802 ListUtils.intersection( dbConsumers, configuration.getRepositoryScanning().getKnownContentConsumers() );
804 if ( !intersec.isEmpty() )
807 List<String> knowContentConsumers =
808 new ArrayList<>( configuration.getRepositoryScanning().getKnownContentConsumers().size() );
809 for ( String knowContentConsumer : configuration.getRepositoryScanning().getKnownContentConsumers() )
811 if ( !dbConsumers.contains( knowContentConsumer ) )
813 knowContentConsumers.add( knowContentConsumer );
817 configuration.getRepositoryScanning().setKnownContentConsumers( knowContentConsumers );
820 // ensure create-archiva-metadata is here
821 if ( !configuration.getRepositoryScanning().getKnownContentConsumers().contains( "create-archiva-metadata" ) )
823 List<String> knowContentConsumers =
824 new ArrayList<>( configuration.getRepositoryScanning().getKnownContentConsumers() );
825 knowContentConsumers.add( "create-archiva-metadata" );
826 configuration.getRepositoryScanning().setKnownContentConsumers( knowContentConsumers );
829 // ensure duplicate-artifacts is here
830 if ( !configuration.getRepositoryScanning().getKnownContentConsumers().contains( "duplicate-artifacts" ) )
832 List<String> knowContentConsumers =
833 new ArrayList<>( configuration.getRepositoryScanning().getKnownContentConsumers() );
834 knowContentConsumers.add( "duplicate-artifacts" );
835 configuration.getRepositoryScanning().setKnownContentConsumers( knowContentConsumers );
838 Registry defaultOnlyConfiguration = readDefaultOnlyConfiguration();
839 // Currently we check only for configuration version change, not certain version numbers.
840 if (hasConfigVersionChanged(configuration, defaultOnlyConfiguration)) {
841 updateCheckPathDefaults(configuration, defaultOnlyConfiguration);
842 String newVersion = defaultOnlyConfiguration.getString("version");
843 if (newVersion==null) {
844 throw new IndeterminateConfigurationException("The default configuration has no version information!");
846 configuration.setVersion(newVersion);
849 } catch (IndeterminateConfigurationException e) {
850 log.error("Error occured during configuration update to new version: {}", e.getMessage());
851 } catch (RegistryException e) {
852 log.error("Error occured during configuration update to new version: {}", e.getMessage());
860 this.configuration = null;
863 this.registry.initialize();
865 catch ( RegistryException e )
867 throw new ConfigurationRuntimeException( e.getMessage(), e );
873 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
875 // nothing to do here
879 public synchronized void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
881 configuration = null;
884 private String removeExpressions( String directory )
886 String value = StringUtils.replace( directory, "${appserver.base}",
887 registry.getString( "appserver.base", "${appserver.base}" ) );
888 value = StringUtils.replace( value, "${appserver.home}",
889 registry.getString( "appserver.home", "${appserver.home}" ) );
893 private String unescapeCronExpression( String cronExpression )
895 return StringUtils.replace( cronExpression, "\\,", "," );
898 private String escapeCronExpression( String cronExpression )
900 return StringUtils.replace( cronExpression, ",", "\\," );
903 private Configuration unescapeExpressions( Configuration config )
905 // TODO: for commons-configuration 1.3 only
906 for ( ManagedRepositoryConfiguration c : config.getManagedRepositories() )
908 c.setLocation( removeExpressions( c.getLocation() ) );
909 c.setRefreshCronExpression( unescapeCronExpression( c.getRefreshCronExpression() ) );
915 private Configuration checkRepositoryLocations( Configuration config )
917 // additional check for [MRM-789], ensure that the location of the default repositories
918 // are not installed in the server installation
919 for ( ManagedRepositoryConfiguration repo : (List<ManagedRepositoryConfiguration>) config.getManagedRepositories() )
921 String repoPath = repo.getLocation();
922 Path repoLocation = Paths.get( repoPath );
924 if ( Files.exists(repoLocation) && Files.isDirectory(repoLocation) && !repoPath.endsWith(
925 "data/repositories/" + repo.getId() ) )
927 repo.setLocation( repoPath + "/data/repositories/" + repo.getId() );
934 public String getUserConfigFilename()
936 return userConfigFilename;
939 public String getAltConfigFilename()
941 return altConfigFilename;
945 public boolean isDefaulted()
947 return this.isConfigurationDefaulted;
950 public Registry getRegistry()
955 public void setRegistry( Registry registry )
957 this.registry = registry;
961 public void setUserConfigFilename( String userConfigFilename )
963 this.userConfigFilename = userConfigFilename;
966 public void setAltConfigFilename( String altConfigFilename )
968 this.altConfigFilename = altConfigFilename;