/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.geronimo.gshell.wisdom.shell;

import jline.History;
import org.apache.geronimo.gshell.application.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;

/**
 * Default implementation of the {@link jline.History} component.
 *
 * @version $Rev$ $Date$
 */
public class HistoryImpl
    extends History
{
    private final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    private Application application;
    
    @PostConstruct
    public void init() {
        assert application != null;
        File file = application.getModel().getBranding().getHistoryFile();
        log.debug("Application configured, setting history file: {}", file);
    }
    
    public void setHistoryFile(final File file) throws IOException {
        assert file != null;

        File dir = file.getParentFile();

        if (!dir.exists()) {
            boolean result = dir.mkdirs();
            if (!result) {
                log.warn("Failed to create base directory for history file: {}", dir);
            }
            else {
                log.debug("Created base directory for history file: {}", dir);
            }
        }

        log.debug("Using history file: {}", file);

        super.setHistoryFile(file);
    }
}
@@ -907,16 +907,131 @@
 .gshell.
+event.EventAdapter;%0Aimport org.apache.geronimo.gshell.event.EventManager;%0Aimport org.apache.geronimo.gshell.wisdom.
 applicat
@@ -1045,16 +1045,31 @@
 lication
+ConfiguredEvent
 ;%0Aimport
@@ -1521,37 +1521,35 @@
 ate 
-Application application;%0A    
+EventManager eventManager;%0A
 %0A   
@@ -1604,27 +1604,246 @@
  assert 
-application
+eventManager != null;%0A        eventManager.addListener(new EventAdapter%3CApplicationConfiguredEvent%3E() %7B%0A            protected void handleEvent(final ApplicationConfiguredEvent event) throws Exception %7B%0A                assert event
  != null
@@ -1844,24 +1844,28 @@
 = null;%0A
+%0A   
         
 File fil
@@ -1852,24 +1852,29 @@
 %0A           
+     
 File file = 
@@ -1873,17 +1873,26 @@
  file = 
-a
+event.getA
 pplicati
@@ -1893,16 +1893,18 @@
 lication
+()
 .getMode
@@ -1935,24 +1935,32 @@
 toryFile();%0A
+        
         log.
@@ -1970,63 +1970,57 @@
 ug(%22
-Application configured, setting history file: %7B%7D%22, file
+History file: %7B%7D%22, file);%0A            %7D%0A        %7D
 );%0A 

Make history work as a singleton again for now