From e764c61109b68e47f3d10e1ff6270446a4d24f19 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Mon, 10 Jul 2006 04:39:44 +0000 Subject: [PATCH] [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 --- maven-repository-configuration/pom.xml | 4 + .../ConfigurationChangeListener.java | 33 +++++ .../configuration/ConfigurationStore.java | 47 +++++++ .../ConfigurationStoreException.java | 36 ++++++ .../DefaultConfigurationStore.java | 119 ++++++++++++++++++ .../src/main/mdo/configuration.mdo | 2 +- maven-repository-webapp/pom.xml | 5 + .../src/main/resources/plexus-application.xml | 94 ++++++++++++++ .../src/main/webapp/WEB-INF/plexus.xml | 117 ----------------- 9 files changed, 339 insertions(+), 118 deletions(-) create mode 100644 maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java create mode 100644 maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java create mode 100644 maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java create mode 100644 maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java create mode 100644 maven-repository-webapp/src/main/resources/plexus-application.xml delete mode 100644 maven-repository-webapp/src/main/webapp/WEB-INF/plexus.xml diff --git a/maven-repository-configuration/pom.xml b/maven-repository-configuration/pom.xml index 72cbf95db..61d989772 100644 --- a/maven-repository-configuration/pom.xml +++ b/maven-repository-configuration/pom.xml @@ -10,6 +10,10 @@ maven-repository-configuration Maven Repository Manager Configuration + + org.codehaus.plexus + plexus-container-default + org.codehaus.plexus plexus-utils diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java new file mode 100644 index 000000000..b02717df2 --- /dev/null +++ b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java @@ -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 Brett Porter + */ +public interface ConfigurationChangeListener +{ + /** + * Notify the object that there has been a configuration change. + * + * @param configuration the new configuration + */ + void notifyOfConfigurationChange( Configuration configuration ); +} diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java new file mode 100644 index 000000000..432062c53 --- /dev/null +++ b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java @@ -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 Brett Porter + * @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; +} diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java new file mode 100644 index 000000000..04dd8990b --- /dev/null +++ b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java @@ -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 Brett Porter + */ +public class ConfigurationStoreException + extends Exception +{ + public ConfigurationStoreException( String message ) + { + super( message ); + } + + public ConfigurationStoreException( String message, Throwable e ) + { + super( message, e ); + } +} diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java new file mode 100644 index 000000000..f8e9908c9 --- /dev/null +++ b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java @@ -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 Brett Porter + * @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/**/ 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" ); + } +} diff --git a/maven-repository-configuration/src/main/mdo/configuration.mdo b/maven-repository-configuration/src/main/mdo/configuration.mdo index 37b2175c5..32501f53d 100644 --- a/maven-repository-configuration/src/main/mdo/configuration.mdo +++ b/maven-repository-configuration/src/main/mdo/configuration.mdo @@ -10,7 +10,7 @@ org.apache.maven.repository.configuration - + Configuration diff --git a/maven-repository-webapp/pom.xml b/maven-repository-webapp/pom.xml index f275853b0..ad9236fde 100644 --- a/maven-repository-webapp/pom.xml +++ b/maven-repository-webapp/pom.xml @@ -42,6 +42,11 @@ plexus-xwork-integration 1.0-alpha-2-SNAPSHOT + + org.codehaus.plexus + plexus-log4j-logging + 1.1-alpha-2 + org.codehaus.plexus plexus-container-default diff --git a/maven-repository-webapp/src/main/resources/plexus-application.xml b/maven-repository-webapp/src/main/resources/plexus-application.xml new file mode 100644 index 000000000..d8d3b78c1 --- /dev/null +++ b/maven-repository-webapp/src/main/resources/plexus-application.xml @@ -0,0 +1,94 @@ + + + + + + + org.codehaus.plexus.logging.LoggerManager + org.codehaus.plexus.logging.log4j.Log4JLoggerManager + basic + + + DEBUG + console + + + console + DEBUG + org.apache.log4j.ConsoleAppender + %d [%t] %-5p %-30c{1} - %m%n + + + + + org.codehaus.plexus.velocity + WARN + + + org.codehaus.plexus.mailsender.MailSender + INFO + + + org.apache.jasper + INFO + + + com.opensymphony.xwork + INFO + + + com.opensymphony.webwork + INFO + + + + + + + + + webapp + + + webapp + Web Application Component Lifecycle Handler + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/plexus.xml b/maven-repository-webapp/src/main/webapp/WEB-INF/plexus.xml deleted file mode 100644 index 852ec21dd..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/plexus.xml +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - com.opensymphony.xwork.ObjectFactory - org.codehaus.plexus.xwork.PlexusObjectFactory - - - - - - -