*/
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;
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;
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" );
+ 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 );
+ }
}
}
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.
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()