]> source.dussan.org Git - archiva.git/commitdiff
[MRM-46] set application up so that configuration can be loaded from a webapp context...
authorBrett Porter <brett@apache.org>
Mon, 10 Jul 2006 04:39:44 +0000 (04:39 +0000)
committerBrett Porter <brett@apache.org>
Mon, 10 Jul 2006 04:39:44 +0000 (04:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@420421 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-configuration/pom.xml
maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java [new file with mode: 0644]
maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java [new file with mode: 0644]
maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java [new file with mode: 0644]
maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java [new file with mode: 0644]
maven-repository-configuration/src/main/mdo/configuration.mdo
maven-repository-webapp/pom.xml
maven-repository-webapp/src/main/resources/plexus-application.xml [new file with mode: 0644]
maven-repository-webapp/src/main/webapp/WEB-INF/plexus.xml [deleted file]

index 72cbf95db5fa75b32827d0c7a99d7f5263b1a30c..61d989772a21aa05f4be51ed9879c2c2906721c6 100644 (file)
   <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>
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 (file)
index 0000000..b02717d
--- /dev/null
@@ -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 );
+}
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 (file)
index 0000000..432062c
--- /dev/null
@@ -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;
+}
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 (file)
index 0000000..04dd899
--- /dev/null
@@ -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 );
+    }
+}
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 (file)
index 0000000..f8e9908
--- /dev/null
@@ -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" );
+    }
+}
index 37b2175c54e855af1bdaa7d1c286aeaa0e529a92..32501f53d1b7bd5458ca8bf20c6061bbb78fd8ac 100644 (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>
index f275853b06663c5f9d89f9fb68fd4af5b9d710b2..ad9236fdeea4bd989cd0df3e910562b8b919a305 100644 (file)
       <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>
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 (file)
index 0000000..d8d3b78
--- /dev/null
@@ -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>
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 (file)
index 852ec21..0000000
+++ /dev/null
@@ -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>