save the configuration

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@421155 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-07-12 06:09:38 +00:00
parent cd7b693b8e
commit bbf080bf9d
5 changed files with 66 additions and 10 deletions

View 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 );
}
}
}

View 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()

View 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>

View 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>

View File

@ -115,3 +115,10 @@
color: red;
font-weight: bold;
}
.actionMessage {
font-weight: bold;
}
sage {
font-weight: bold;
}