From 127f7fc09b0f37ddd03175da6f31a2d1eaf31922 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 27 Apr 2011 10:02:25 +0200 Subject: [PATCH] improve mercurial configuration wizard --- .../api/rest/resources/HgConfigResource.java | 28 +++++++- .../scm/repository/HgRepositoryHandler.java | 64 +++++++------------ .../resources/sonia/scm/hg.config-wizard.js | 34 +++++++--- .../src/main/resources/sonia/scm/hg.config.js | 8 +-- 4 files changed, 78 insertions(+), 56 deletions(-) diff --git a/plugins/scm-hg-plugin/src/main/java/sonia/scm/api/rest/resources/HgConfigResource.java b/plugins/scm-hg-plugin/src/main/java/sonia/scm/api/rest/resources/HgConfigResource.java index 804faa2e48..a19d6605ed 100644 --- a/plugins/scm-hg-plugin/src/main/java/sonia/scm/api/rest/resources/HgConfigResource.java +++ b/plugins/scm-hg-plugin/src/main/java/sonia/scm/api/rest/resources/HgConfigResource.java @@ -98,11 +98,33 @@ public class HgConfigResource */ @POST @Path("auto-configuration") - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public HgConfig autoConfiguration(@Context UriInfo uriInfo) { - handler.setConfig(null); - handler.doAutoConfiguration(); + return autoConfiguration(uriInfo, null); + } + + /** + * Method description + * + * + * @param uriInfo + * @param config + * + * @return + */ + @POST + @Path("auto-configuration") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public HgConfig autoConfiguration(@Context UriInfo uriInfo, HgConfig config) + { + if (config == null) + { + config = new HgConfig(); + } + + handler.doAutoConfiguration(config); return handler.getConfig(); } diff --git a/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java b/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java index c690b92127..779f4cc160 100644 --- a/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java +++ b/plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java @@ -104,55 +104,35 @@ public class HgRepositoryHandler /** * Method description * + * + * @param autoConfig */ - public void doAutoConfiguration() + public void doAutoConfiguration(HgConfig autoConfig) { HgInstaller installer = HgInstallerFactory.createInstaller(); - if (config == null) + try { - config = new HgConfig(); - - try + if (logger.isDebugEnabled()) { - if (logger.isDebugEnabled()) - { - logger.debug("installing mercurial with {}", - installer.getClass().getName()); - } - - installer.install(baseDirectory, config); - new HgWebConfigWriter(config).write(); + logger.debug("installing mercurial with {}", + installer.getClass().getName()); } - catch (IOException ioe) + + installer.install(baseDirectory, autoConfig); + config = autoConfig; + storeConfig(); + new HgWebConfigWriter(config).write(); + } + catch (IOException ioe) + { + if (logger.isErrorEnabled()) { - if (logger.isErrorEnabled()) - { - logger.error( - "Could not write Hg CGI for inital config. " - + "HgWeb may not function until a new Hg config is set", ioe); - } + logger.error( + "Could not write Hg CGI for inital config. " + + "HgWeb may not function until a new Hg config is set", ioe); } } - else - { - try - { - if (logger.isDebugEnabled()) - { - logger.debug("update mercurial with {}", - installer.getClass().getName()); - } - - installer.update(baseDirectory, config); - } - catch (IOException ex) - { - logger.error(ex.getMessage(), ex); - } - } - - storeConfig(); } /** @@ -163,7 +143,11 @@ public class HgRepositoryHandler public void loadConfig() { super.loadConfig(); - doAutoConfiguration(); + + if (config == null) + { + doAutoConfiguration(new HgConfig()); + } } //~--- get methods ---------------------------------------------------------- diff --git a/plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config-wizard.js b/plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config-wizard.js index a3b74ce969..c5094e3937 100644 --- a/plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config-wizard.js +++ b/plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config-wizard.js @@ -170,13 +170,7 @@ Sonia.hg.ConfigWizardPanel = Ext.extend(Ext.Panel,{ },{ id: 'finish', text: 'Finish', - handler: function(){ - if ( debug ){ - console.debug('finish'); - console.debug( this.hgConfig ); - } - this.fireEvent('finish', this.hgConfig); - }, + handler: this.applyChanges, scope: this, disabled: true }], @@ -184,6 +178,7 @@ Sonia.hg.ConfigWizardPanel = Ext.extend(Ext.Panel,{ id: 'step-1', layout: 'form', items: [{ + id: 'mercurial', fieldLabel: 'Mercurial Installation', name: 'mercurial', xtype: 'combo', @@ -195,8 +190,10 @@ Sonia.hg.ConfigWizardPanel = Ext.extend(Ext.Panel,{ store: hgInstallationStore, valueField: 'path', displayField: 'path', - allowBlank: false + allowBlank: false, + value: this.hgConfig.hgBinary },{ + id: 'python', fieldLabel: 'Python Installation', name: 'python', xtype: 'combo', @@ -208,7 +205,8 @@ Sonia.hg.ConfigWizardPanel = Ext.extend(Ext.Panel,{ store: pythonInstallationStore, valueField: 'path', displayField: 'path', - allowBlank: false + allowBlank: false, + value: this.hgConfig.pythonBinary }] },{ id: 'step-2', @@ -221,6 +219,24 @@ Sonia.hg.ConfigWizardPanel = Ext.extend(Ext.Panel,{ Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.hg.ConfigWizardPanel.superclass.initComponent.apply(this, arguments); + }, + + applyChanges: function(){ + var mercurial = Ext.getCmp('mercurial').getValue(); + var python = Ext.getCmp('python').getValue(); + if (debug){ + console.debug( 'configure mercurial=' + mercurial + " and python=" + python ); + } + delete this.hgConfig.pythonPath; + delete this.hgConfig.useOptimizedBytecode; + this.hgConfig.hgBinary = mercurial; + this.hgConfig.pythonBinary = python; + + if ( debug ){ + console.debug( this.hgConfig ); + } + + this.fireEvent('finish', this.hgConfig); } }); diff --git a/plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config.js b/plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config.js index db098705ac..50b3b82918 100644 --- a/plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config.js +++ b/plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg.config.js @@ -104,10 +104,9 @@ Sonia.hg.ConfigPanel = Ext.extend(Sonia.config.ConfigForm, { wizard.on('finish', function(config){ if (debug){ console.debug( 'load config from wizard and submit to server' ); - console.debug( config ); } - this.getForm().load(config); - this.onSubmit(config); + var self = Ext.getCmp('hgConfigForm'); + self.loadConfig( self.el, 'config/repositories/hg/auto-configuration.json', 'POST', config ); }, this); wizard.show(); }, @@ -141,11 +140,12 @@ Sonia.hg.ConfigPanel = Ext.extend(Sonia.config.ConfigForm, { this.loadConfig(el, 'config/repositories/hg.json', 'GET'); }, - loadConfig: function(el, url, method){ + loadConfig: function(el, url, method, config){ var tid = setTimeout( function(){ el.mask(this.loadingText); }, 100); Ext.Ajax.request({ url: restUrl + url, method: method, + jsonData: config, scope: this, disableCaching: true, success: function(response){