[MRM-46] set application up so that configuration can be loaded from a webapp context param (using expressions)

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@420421 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-07-10 04:39:44 +00:00
parent f8ed8907af
commit e764c61109
9 changed files with 339 additions and 118 deletions

View File

@ -10,6 +10,10 @@
<artifactId>maven-repository-configuration</artifactId>
<name>Maven Repository Manager Configuration</name>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>

View File

@ -0,0 +1,33 @@
package org.apache.maven.repository.configuration;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed 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.
*/
/**
* Component capable of noticing configuration changes and adjusting accordingly.
* This is not a Plexus role.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public interface ConfigurationChangeListener
{
/**
* Notify the object that there has been a configuration change.
*
* @param configuration the new configuration
*/
void notifyOfConfigurationChange( Configuration configuration );
}

View File

@ -0,0 +1,47 @@
package org.apache.maven.repository.configuration;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed 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.
*/
/**
* A component for loading the configuration into the model.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @todo this is something that could possibly be generalised into Modello.
*/
public interface ConfigurationStore
{
/**
* The Plexus role for the component.
*/
String ROLE = ConfigurationStore.class.getName();
/**
* Get the configuration from the store. A cached version may be used.
*
* @return the configuration
*/
Configuration getConfigurationFromStore()
throws ConfigurationStoreException;
/**
* Save the configuration to the store.
*
* @param configuration the configuration to store
*/
void storeConfiguration( Configuration configuration )
throws ConfigurationStoreException;
}

View File

@ -0,0 +1,36 @@
package org.apache.maven.repository.configuration;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed 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.
*/
/**
* Exception occurring using the configuration store.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class ConfigurationStoreException
extends Exception
{
public ConfigurationStoreException( String message )
{
super( message );
}
public ConfigurationStoreException( String message, Throwable e )
{
super( message, e );
}
}

View File

@ -0,0 +1,119 @@
package org.apache.maven.repository.configuration;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed 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.maven.repository.configuration.io.xpp3.ConfigurationXpp3Reader;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**
* Load and store the configuration. No synchronization is used, but it is unnecessary as the old configuration object
* can continue to be used.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @todo would be great for plexus to do this for us - so the configuration would be a component itself rather than this store
* @todo would be good to monitor the store file for changes
* @todo support other implementations than XML file
* @plexus.component role="org.apache.maven.repository.configuration.ConfigurationStore" role-hint="default"
*/
public class DefaultConfigurationStore
extends AbstractLogEnabled
implements ConfigurationStore
{
/**
* @plexus.configuration default-value="${configuration.store.file}"
*/
private File file;
/**
* The cached configuration.
*/
private Configuration configuration;
/**
* List of listeners to configuration changes.
*/
private List/*<ConfigurationChangeListener>*/ listeners = new LinkedList();
public Configuration getConfigurationFromStore()
throws ConfigurationStoreException
{
if ( configuration == null )
{
ConfigurationXpp3Reader reader = new ConfigurationXpp3Reader();
if ( file == null )
{
file = new File( System.getProperty( "user.home" ), "/.m2/repository-manager.xml" );
}
FileReader fileReader;
try
{
fileReader = new FileReader( file );
}
catch ( FileNotFoundException e )
{
getLogger().warn( "Configuration file: " + file + " not found. Using defaults." );
configuration = new Configuration();
return configuration;
}
try
{
configuration = reader.read( fileReader );
}
catch ( IOException e )
{
throw new ConfigurationStoreException( e.getMessage(), e );
}
catch ( XmlPullParserException e )
{
throw new ConfigurationStoreException( e.getMessage(), e );
}
finally
{
IOUtil.close( fileReader );
}
}
return configuration;
}
public void storeConfiguration( Configuration configuration )
throws ConfigurationStoreException
{
// TODO: finish!
for ( Iterator i = listeners.iterator(); i.hasNext(); )
{
ConfigurationChangeListener listener = (ConfigurationChangeListener) i.next();
listener.notifyOfConfigurationChange( configuration );
}
throw new UnsupportedOperationException( "Not yet implemented: storeConfiguration" );
}
}

View File

@ -10,7 +10,7 @@
<value>org.apache.maven.repository.configuration</value>
</default>
</defaults>
<!-- TODO! break out subtypes such as <discovery> and create a list of blacklist -->
<!-- TODO! break out subtypes such as <discovery> and create a list of blacklist, have multiple repositories -->
<classes>
<class rootElement="true" xml.tagName="configuration">
<name>Configuration</name>

View File

@ -42,6 +42,11 @@
<artifactId>plexus-xwork-integration</artifactId>
<version>1.0-alpha-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-log4j-logging</artifactId>
<version>1.1-alpha-2</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>

View File

@ -0,0 +1,94 @@
<!--
~ Copyright 2005-2006 The Apache Software Foundation.
~
~ Licensed 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.
-->
<plexus>
<components>
<!--
| Logger manager
-->
<component>
<role>org.codehaus.plexus.logging.LoggerManager</role>
<implementation>org.codehaus.plexus.logging.log4j.Log4JLoggerManager</implementation>
<lifecycle-handler>basic</lifecycle-handler>
<configuration>
<threshold>DEBUG</threshold>
<default-appender>console</default-appender>
<appenders>
<appender>
<id>console</id>
<threshold>DEBUG</threshold>
<type>org.apache.log4j.ConsoleAppender</type>
<conversion-pattern>%d [%t] %-5p %-30c{1} - %m%n</conversion-pattern>
</appender>
</appenders>
<levels>
<level>
<hierarchy>org.codehaus.plexus.velocity</hierarchy>
<level>WARN</level>
</level>
<level>
<hierarchy>org.codehaus.plexus.mailsender.MailSender</hierarchy>
<level>INFO</level>
</level>
<level>
<hierarchy>org.apache.jasper</hierarchy>
<level>INFO</level>
</level>
<level>
<hierarchy>com.opensymphony.xwork</hierarchy>
<level>INFO</level>
</level>
<level>
<hierarchy>com.opensymphony.webwork</hierarchy>
<level>INFO</level>
</level>
</levels>
</configuration>
</component>
</components>
<!-- Override default configuration of components -->
<lifecycle-handler-manager implementation="org.codehaus.plexus.lifecycle.DefaultLifecycleHandlerManager">
<default-lifecycle-handler-id>webapp</default-lifecycle-handler-id>
<lifecycle-handlers>
<lifecycle-handler implementation="org.codehaus.plexus.personality.plexus.PlexusLifecycleHandler">
<id>webapp</id>
<name>Web Application Component Lifecycle Handler</name>
<begin-segment>
<phase implementation="org.codehaus.plexus.personality.plexus.lifecycle.phase.LogEnablePhase"/>
<phase implementation="org.codehaus.plexus.personality.plexus.lifecycle.phase.CompositionPhase"/>
<phase implementation="org.codehaus.plexus.personality.plexus.lifecycle.phase.ContextualizePhase"/>
<phase implementation="org.codehaus.plexus.xwork.ConfigurationPhase"/>
<phase implementation="org.codehaus.plexus.personality.plexus.lifecycle.phase.ServiceablePhase"/>
<phase implementation="org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializePhase"/>
<phase implementation="org.codehaus.plexus.personality.plexus.lifecycle.phase.StartPhase"/>
</begin-segment>
<suspend-segment>
<phase implementation="org.codehaus.plexus.personality.plexus.lifecycle.phase.SuspendPhase"/>
</suspend-segment>
<resume-segment>
<phase implementation="org.codehaus.plexus.personality.plexus.lifecycle.phase.ResumePhase"/>
</resume-segment>
<end-segment>
<phase implementation="org.codehaus.plexus.personality.plexus.lifecycle.phase.StopPhase"/>
<phase implementation="org.codehaus.plexus.personality.plexus.lifecycle.phase.DisposePhase"/>
<phase implementation="org.codehaus.plexus.personality.plexus.lifecycle.phase.LogDisablePhase"/>
</end-segment>
</lifecycle-handler>
</lifecycle-handlers>
</lifecycle-handler-manager>
</plexus>

View File

@ -1,117 +0,0 @@
<!--
~ Copyright 2005-2006 The Apache Software Foundation.
~
~ Licensed 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.
-->
<plexus>
<!--
<load-on-start>
<component>
<role>org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor</role>
<role-hint>build-project</role-hint>
</component>
<component>
<role>org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor</role>
<role-hint>check-out-project</role-hint>
</component>
</load-on-start>
-->
<components>
<!--
| Object factory for WebWork
-->
<component>
<role>com.opensymphony.xwork.ObjectFactory</role>
<implementation>org.codehaus.plexus.xwork.PlexusObjectFactory</implementation>
</component>
<!--
| Logger manager
-->
<!--
<component>
<role>org.codehaus.plexus.logging.LoggerManager</role>
<implementation>org.codehaus.plexus.logging.log4j.Log4JLoggerManager</implementation>
<lifecycle-handler>basic</lifecycle-handler>
<configuration>
<threshold>DEBUG</threshold>
<default-appender>console,rolling</default-appender>
<appenders>
<appender>
<id>console</id>
<threshold>DEBUG</threshold>
<type>org.apache.log4j.ConsoleAppender</type>
<conversion-pattern>%d [%t] %-5p %-30c{1} - %m%n</conversion-pattern>
</appender>
<appender>
<id>rolling</id>
<threshold>DEBUG</threshold>
<type>org.apache.log4j.RollingFileAppender</type>
<conversion-pattern>%-4r [%t] %-5p %c %x - %m%n</conversion-pattern>
<properties>
<property>
<name>file</name>
<value>${plexus.home}/logs/continuum.log</value>
</property>
<property>
<name>append</name>
<value>true</value>
</property>
<property>
<name>maxBackupIndex</name>
<value>10</value>
</property>
<property>
<name>maxFileSize</name>
<value>10MB</value>
</property>
</properties>
</appender>
</appenders>
<levels>
<level>
<hierarchy>org.codehaus.plexus.velocity</hierarchy>
<level>WARN</level>
</level>
<level>
<hierarchy>org.codehaus.plexus.mailsender.MailSender</hierarchy>
<level>INFO</level>
</level>
<level>
<hierarchy>org.apache.jasper</hierarchy>
<level>INFO</level>
</level>
<level>
<hierarchy>com.opensymphony.xwork</hierarchy>
<level>INFO</level>
</level>
<level>
<hierarchy>com.opensymphony.webwork</hierarchy>
<level>INFO</level>
</level>
</levels>
</configuration>
</component>
-->
</components>
</plexus>