1 package org.apache.maven.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.maven.archiva.configuration.io.registry.ConfigurationRegistryReader;
23 import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryWriter;
24 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
25 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
26 import org.codehaus.plexus.registry.Registry;
27 import org.codehaus.plexus.registry.RegistryException;
28 import org.codehaus.plexus.registry.RegistryListener;
29 import org.codehaus.plexus.util.StringUtils;
31 import java.util.Iterator;
34 * Implementation of configuration holder that retrieves it from the registry.
38 public class DefaultArchivaConfiguration
39 implements ArchivaConfiguration, RegistryListener, Initializable
42 * Plexus registry to read the configuration from.
44 * @plexus.requirement role-hint="commons-configuration"
46 private Registry registry;
49 * The configuration that has been converted.
51 private Configuration configuration;
53 private static final String KEY = "org.apache.maven.archiva";
55 public synchronized Configuration getConfiguration()
57 if ( configuration == null )
59 // TODO: should this be the same as section? make sure unnamed sections still work (eg, sys properties)
60 configuration = new ConfigurationRegistryReader().read( registry.getSubset( KEY ) );
62 // TODO: for commons-configuration 1.3 only
63 configuration.setIndexPath( removeExpressions( configuration.getIndexPath() ) );
64 configuration.setMinimalIndexPath( removeExpressions( configuration.getMinimalIndexPath() ) );
65 configuration.setLocalRepository( removeExpressions( configuration.getLocalRepository() ) );
66 for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); )
68 RepositoryConfiguration c = (RepositoryConfiguration) i.next();
69 c.setDirectory( removeExpressions( c.getDirectory() ) );
75 public void save( Configuration configuration )
76 throws RegistryException
78 Registry section = registry.getSection( KEY + ".user" );
79 if ( section == null )
81 section = registry.getSection( KEY + ".base" );
83 new ConfigurationRegistryWriter().write( configuration, section );
86 this.configuration = configuration;
89 public void addChangeListener( RegistryListener listener )
91 Registry section = registry.getSection( KEY + ".user" );
92 if ( section != null )
94 section.addChangeListener( listener );
96 section = registry.getSection( KEY + ".base" );
97 if ( section != null )
99 section.addChangeListener( listener );
103 public void initialize()
104 throws InitializationException
106 registry.addChangeListener( this );
109 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
111 // nothing to do here
114 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
116 configuration = null;
119 private String removeExpressions( String directory )
121 String value = StringUtils.replace( directory, "${appserver.base}",
122 registry.getString( "appserver.base", "${appserver.base}" ) );
123 value = StringUtils.replace( value, "${appserver.home}",
124 registry.getString( "appserver.home", "${appserver.home}" ) );