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 for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); )
65 RepositoryConfiguration c = (RepositoryConfiguration) i.next();
66 c.setUrl( removeExpressions( c.getUrl() ) );
72 public void save( Configuration configuration )
73 throws RegistryException
75 Registry section = registry.getSection( KEY + ".user" );
76 if ( section == null )
78 section = registry.getSection( KEY + ".base" );
80 new ConfigurationRegistryWriter().write( configuration, section );
83 this.configuration = configuration;
86 public void addChangeListener( RegistryListener listener )
88 Registry section = registry.getSection( KEY + ".user" );
89 if ( section != null )
91 section.addChangeListener( listener );
93 section = registry.getSection( KEY + ".base" );
94 if ( section != null )
96 section.addChangeListener( listener );
100 public void initialize()
101 throws InitializationException
103 registry.addChangeListener( this );
106 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
108 // nothing to do here
111 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
113 configuration = null;
116 private String removeExpressions( String directory )
118 String value = StringUtils.replace( directory, "${appserver.base}",
119 registry.getString( "appserver.base", "${appserver.base}" ) );
120 value = StringUtils.replace( value, "${appserver.home}",
121 registry.getString( "appserver.home", "${appserver.home}" ) );