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
index f8e9908c9..f10588f82 100644
--- 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
@@ -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 );
+ }
}
}
diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java
index f19b1baa9..433d0ee81 100644
--- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java
+++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java
@@ -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()
diff --git a/maven-repository-webapp/src/main/resources/xwork.xml b/maven-repository-webapp/src/main/resources/xwork.xml
index 635ec2da6..85390a2df 100644
--- a/maven-repository-webapp/src/main/resources/xwork.xml
+++ b/maven-repository-webapp/src/main/resources/xwork.xml
@@ -96,7 +96,7 @@