@@ -140,7 +140,7 @@ public String getUrlName() {
140140
141141 @ Override
142142 public String getDescription () {
143- return "Reload your configuration or update configuration source" ;
143+ return "Reload your configuration or update configuration source. " ;
144144 }
145145
146146 /**
@@ -218,38 +218,51 @@ public void doReplace(StaplerRequest2 request, StaplerResponse2 response) throws
218218 response .sendError (HttpServletResponse .SC_FORBIDDEN );
219219 return ;
220220 }
221- String newSource = request .getParameter ("_.newSource" );
222- String normalizedSource = Util .fixEmptyAndTrim (newSource );
223- List <String > candidateSources = new ArrayList <>();
224- for (String candidateSource : inputToCandidateSources (normalizedSource )) {
225- File file = new File (candidateSource );
226- if (file .exists () || ConfigurationAsCode .isSupportedURI (candidateSource )) {
227- candidateSources .add (candidateSource );
228- } else {
229- LOGGER .log (Level .WARNING , "Source {0} could not be applied" , candidateSource );
230- // todo: show message in UI
221+ try {
222+ String newSource = request .getParameter ("_.newSource" );
223+ String normalizedSource = Util .fixEmptyAndTrim (newSource );
224+ List <String > candidateSources = new ArrayList <>();
225+ for (String candidateSource : inputToCandidateSources (normalizedSource )) {
226+ File file = new File (candidateSource );
227+ if (file .exists () || ConfigurationAsCode .isSupportedURI (candidateSource )) {
228+ candidateSources .add (candidateSource );
229+ } else {
230+ LOGGER .log (Level .WARNING , "Source {0} could not be applied" , candidateSource );
231+ // todo: show message in UI
232+ }
231233 }
232- }
233- if (!candidateSources .isEmpty ()) {
234- List <YamlSource > candidates = getConfigFromSources (candidateSources );
235- if (canApplyFrom (candidates )) {
236- sources = candidateSources ;
237- configureWith (getConfigFromSources (getSources ()));
238- CasCGlobalConfig config = GlobalConfiguration .all ().get (CasCGlobalConfig .class );
239- if (config != null ) {
240- config .setConfigurationPath (normalizedSource );
241- config .save ();
234+ if (!candidateSources .isEmpty ()) {
235+ List <YamlSource > candidates = getConfigFromSources (candidateSources );
236+ if (canApplyFrom (candidates )) {
237+ sources = candidateSources ;
238+ configureWith (getConfigFromSources (getSources ()));
239+ CasCGlobalConfig config = GlobalConfiguration .all ().get (CasCGlobalConfig .class );
240+ if (config != null ) {
241+ config .setConfigurationPath (normalizedSource );
242+ config .save ();
243+ }
244+ LOGGER .log (Level .FINE , "Replace configuration with: " + normalizedSource );
245+ } else {
246+ LOGGER .log (Level .WARNING , "Provided sources could not be applied" );
247+ // todo: show message in UI
242248 }
243- LOGGER .log (Level .FINE , "Replace configuration with: " + normalizedSource );
244249 } else {
245- LOGGER .log (Level .WARNING , "Provided sources could not be applied" );
246- // todo: show message in UI
250+ LOGGER .log (Level .FINE , "No such source exists, applying default" );
251+ // May be do nothing instead?
252+ configure ();
247253 }
248- } else {
249- LOGGER .log (Level .FINE , "No such source exists, applying default" );
250- // May be do nothing instead?
251- configure ();
254+ } catch (ConfiguratorException e ) {
255+ LOGGER .log (Level .SEVERE , "Failed to reload configuration" , e );
256+
257+ Throwable throwableCause = e .getCause ();
258+ if (throwableCause instanceof ConfiguratorException cause ) {
259+ handleExceptionOnReloading (request , response , cause );
260+ } else {
261+ handleExceptionOnReloading (request , response , e );
262+ }
263+ return ;
252264 }
265+
253266 response .sendRedirect ("" );
254267 }
255268
@@ -556,7 +569,23 @@ public void doViewExport(StaplerRequest2 req, StaplerResponse2 res) throws Excep
556569 ByteArrayOutputStream out = new ByteArrayOutputStream ();
557570 export (out );
558571
559- req .setAttribute ("export" , out .toString (StandardCharsets .UTF_8 .name ()));
572+ req .setAttribute ("viewExport" , new ManagementLink () {
573+ @ Override
574+ public String getIconFileName () {
575+ return "" ;
576+ }
577+
578+ // TODO - FIX - EXTREMELY HACKY - couldn't expose a public method for some reason
579+ @ Override
580+ public String getUrlName () {
581+ return out .toString (StandardCharsets .UTF_8 );
582+ }
583+
584+ @ Override
585+ public String getDisplayName () {
586+ return "Export configuration" ;
587+ }
588+ });
560589 req .getView (this , "viewExport.jelly" ).forward (req , res );
561590 }
562591
0 commit comments