]> source.dussan.org Git - archiva.git/commitdiff
save the configuration
authorBrett Porter <brett@apache.org>
Wed, 12 Jul 2006 06:09:38 +0000 (06:09 +0000)
committerBrett Porter <brett@apache.org>
Wed, 12 Jul 2006 06:09:38 +0000 (06:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@421155 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java
maven-repository-webapp/src/main/resources/xwork.xml
maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp
maven-repository-webapp/src/main/webapp/css/site.css

index f8e9908c9ddc316e582dc31623be94b76d69f045..f10588f82f24b467ccbe15f96a84ab02fb106439 100644 (file)
@@ -17,6 +17,7 @@ package org.apache.maven.repository.configuration;
  */
 
 import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Reader;
+import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Writer;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -24,6 +25,7 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -105,8 +107,6 @@ public class DefaultConfigurationStore
     public void storeConfiguration( Configuration configuration )
         throws ConfigurationStoreException
     {
-        // TODO: finish!
-
         for ( Iterator i = listeners.iterator(); i.hasNext(); )
         {
             ConfigurationChangeListener listener = (ConfigurationChangeListener) i.next();
@@ -114,6 +114,21 @@ public class DefaultConfigurationStore
             listener.notifyOfConfigurationChange( configuration );
         }
 
-        throw new UnsupportedOperationException( "Not yet implemented: storeConfiguration" );
+        ConfigurationXpp3Writer writer = new ConfigurationXpp3Writer();
+
+        FileWriter fileWriter = null;
+        try
+        {
+            fileWriter = new FileWriter( file );
+            writer.write( fileWriter, configuration );
+        }
+        catch ( IOException e )
+        {
+            throw new ConfigurationStoreException( e.getMessage(), e );
+        }
+        finally
+        {
+            IOUtil.close( fileWriter );
+        }
     }
 }
index f19b1baa90f044226c3ebaf891605ef4598ee120..433d0ee817ce79bba6ea8a3bfa4cdd34ee2d94f3 100644 (file)
@@ -24,8 +24,10 @@ import org.apache.maven.repository.configuration.ConfigurationStore;
 import org.apache.maven.repository.configuration.ConfigurationStoreException;
 import org.apache.maven.repository.indexing.RepositoryIndexException;
 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
+import org.codehaus.plexus.util.StringUtils;
 
-import java.net.MalformedURLException;
+import java.io.File;
+import java.io.IOException;
 
 /**
  * Configures the application.
@@ -47,11 +49,42 @@ public class ConfigureAction
     private Configuration configuration;
 
     public String execute()
-        throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException,
-        ConfigurationStoreException
+        throws IOException, RepositoryIndexException, RepositoryIndexSearchException, ConfigurationStoreException
     {
-        // TODO! not yet implemented
-        return ERROR;
+        // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded
+
+        // Normalize the path
+        File file = new File( configuration.getRepositoryDirectory() );
+        configuration.setRepositoryDirectory( file.getCanonicalPath() );
+        if ( !file.exists() )
+        {
+            file.mkdirs();
+            // TODO: error handling when this fails
+        }
+
+        // TODO: these defaults belong in the model. They shouldn't be stored here, as you want them to re-default
+        // should the repository change even if these didn't
+
+        // TODO: these should be on an advanced configuration form, not the standard one
+        if ( StringUtils.isEmpty( configuration.getIndexPath() ) )
+        {
+            configuration.setIndexPath(
+                new File( configuration.getRepositoryDirectory(), ".index" ).getAbsolutePath() );
+        }
+        if ( StringUtils.isEmpty( configuration.getMinimalIndexPath() ) )
+        {
+            configuration.setMinimalIndexPath(
+                new File( configuration.getRepositoryDirectory(), ".index-minimal" ).getAbsolutePath() );
+        }
+
+        // Just double checking that our validation routines line up with what is expected in the configuration
+        assert configuration.isValid();
+
+        configurationStore.storeConfiguration( configuration );
+
+        addActionMessage( "Successfully saved configuration" );
+
+        return SUCCESS;
     }
 
     public String doInput()
index 635ec2da6c4b570880bff93a9f4c9390cc3ebf40..85390a2df27114ce55912b3cbf9604fd2b10bd83 100644 (file)
@@ -96,7 +96,7 @@
 
     <action name="saveConfiguration" class="configureAction">
       <result name="input">/WEB-INF/jsp/admin/configure.jsp</result>
-      <!-- TODO: need a SUCCESS handler! -->
+      <result>/WEB-INF/jsp/admin/configure.jsp</result>
     </action>
   </package>
 </xwork>
index 0c6f9ed9d480d2abd9b95d512d4182c6d514b44f..2e6ffec66085bbe34863edeece668894bc211a32 100644 (file)
@@ -27,8 +27,9 @@
 
 <div id="contentArea">
   <div id="searchBox">
+    <ww:actionmessage />
     <ww:form method="post" action="saveConfiguration" namespace="/admin" validate="true">
-      <ww:textfield name="repositoryDirectory" label="Repository Directory" />
+      <ww:textfield name="repositoryDirectory" label="Repository Directory" size="100" />
       <ww:textfield name="discoveryCronExpression" label="Discovery Cron Expression" />
       <ww:submit value="Save Configuration" />
     </ww:form>
index ed9f565799fb3aeb1d580e1b54b370dcf7f5843e..877d3da3fdb1c11552782253fba3989ceb02056f 100644 (file)
     color: red;
     font-weight: bold;
 }
+
+.actionMessage {
+    font-weight: bold;
+}
+sage {
+    font-weight: bold;
+}