public void save( File file )
throws ContinuumConfigurationException
{
try
{
ContinuumConfigurationModel configurationModel = new ContinuumConfigurationModel();
configurationModel.setBaseUrl( this.generalConfiguration.getBaseUrl() );
configurationModel.setNumberOfBuildsInParallel( this.generalConfiguration.getNumberOfBuildsInParallel() );
configurationModel.setSharedSecretPassword( this.generalConfiguration.getSharedSecretPassword() );
// normally not null but NPE free is better !
if ( this.generalConfiguration.getBuildOutputDirectory() != null )
{
configurationModel.setBuildOutputDirectory(
this.generalConfiguration.getBuildOutputDirectory().getPath() );
}
if ( this.generalConfiguration.getWorkingDirectory() != null )
{
configurationModel.setWorkingDirectory( this.generalConfiguration.getWorkingDirectory().getPath() );
}
if ( this.generalConfiguration.getDeploymentRepositoryDirectory() != null )
{
configurationModel.setDeploymentRepositoryDirectory(
this.generalConfiguration.getDeploymentRepositoryDirectory().getPath() );
}
if ( this.generalConfiguration.getProxyConfiguration() != null )
{
configurationModel.setProxyConfiguration(
new org.apache.continuum.configuration.model.ProxyConfiguration() );
configurationModel.getProxyConfiguration().setProxyHost(
this.generalConfiguration.getProxyConfiguration().getProxyHost() );
configurationModel.getProxyConfiguration().setProxyPassword(
this.generalConfiguration.getProxyConfiguration().getProxyPassword() );
configurationModel.getProxyConfiguration().setProxyPort(
this.generalConfiguration.getProxyConfiguration().getProxyPort() );
configurationModel.getProxyConfiguration().setProxyHost(
this.generalConfiguration.getProxyConfiguration().getProxyHost() );
}
if ( this.generalConfiguration.getReleaseOutputDirectory() != null )
{
configurationModel.setReleaseOutputDirectory(
this.generalConfiguration.getReleaseOutputDirectory().getPath() );
}
// set configuration for distributedBuildEnabled.
configurationModel.setDistributedBuildEnabled( this.generalConfiguration.isDistributedBuildEnabled() );
configurationModel.setInitialized( this.generalConfiguration.isInitialized() );
if ( this.generalConfiguration.getBuildAgents() != null )
{
List<org.apache.continuum.configuration.model.BuildAgentConfiguration> buildAgents =
new ArrayList<org.apache.continuum.configuration.model.BuildAgentConfiguration>();
for ( BuildAgentConfiguration agent : this.generalConfiguration.getBuildAgents() )
{
org.apache.continuum.configuration.model.BuildAgentConfiguration buildAgent =
new org.apache.continuum.configuration.model.BuildAgentConfiguration();
buildAgent.setUrl( agent.getUrl() );
buildAgent.setDescription( agent.getDescription() );
buildAgent.setEnabled( agent.isEnabled() );
buildAgents.add( buildAgent );
}
configurationModel.setBuildAgents( buildAgents );
}
if ( this.generalConfiguration.getBuildAgentGroups() != null )
{
List<org.apache.continuum.configuration.model.BuildAgentGroupConfiguration> buildAgentGroups =
new ArrayList<org.apache.continuum.configuration.model.BuildAgentGroupConfiguration>();
for ( BuildAgentGroupConfiguration group : this.generalConfiguration.getBuildAgentGroups() )
{
org.apache.continuum.configuration.model.BuildAgentGroupConfiguration buildAgentGroup =
new org.apache.continuum.configuration.model.BuildAgentGroupConfiguration();
buildAgentGroup.setName( group.getName() );
List<org.apache.continuum.configuration.model.BuildAgentConfiguration> buildAgents =
new ArrayList<org.apache.continuum.configuration.model.BuildAgentConfiguration>();
if ( group.getBuildAgents() != null )
{
for ( BuildAgentConfiguration agent : group.getBuildAgents() )
{
org.apache.continuum.configuration.model.BuildAgentConfiguration buildAgent =
new org.apache.continuum.configuration.model.BuildAgentConfiguration();
buildAgent.setUrl( agent.getUrl() );
buildAgent.setDescription( agent.getDescription() );
buildAgent.setEnabled( agent.isEnabled() );
buildAgents.add( buildAgent );
}
buildAgentGroup.setBuildAgents( buildAgents );
}
buildAgentGroups.add( buildAgentGroup );
}
configurationModel.setBuildAgentGroups( buildAgentGroups );
}
ContinuumConfigurationModelXpp3Writer writer = new ContinuumConfigurationModelXpp3Writer();
FileWriter fileWriter = new FileWriter( file );
writer.write( fileWriter, configurationModel );