/*
 * Copyright 2014-2016 the original author or authors.
 *
 * Licensed 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.dbflute.intro.app.logic.engine;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.dbflute.intro.app.logic.intro.IntroPhysicalLogic;

/**
 * @author p1us2er0
 * @author jflute
 */
public class EngineInfoLogic {

    @Resource
    private IntroPhysicalLogic introPhysicalLogic;

    public List<String> getExistingVersionList() {
        try {
            List<String> list = Files.list(Paths.get(introPhysicalLogic.buildMydbflutePath())).filter(file -> {
                return file.toFile().isDirectory() && file.toFile().getName().startsWith("dbflute-");
            }).map(file -> file.toFile().getName().substring(8)).sorted(Comparator.reverseOrder()).collect(Collectors.toList());
            return list;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

@@ -739,16 +739,73 @@
 ile.Path
+;%0Aimport java.nio.file.Paths;%0Aimport java.util.Collection
 s;%0Aimpor
@@ -1192,148 +1192,402 @@
     
-try %7B%0A            List%3CString%3E list = Files.list(Paths.get(introPhysicalLogic.buildMydbflutePath())).filter(file -%3E %7B%0A                return
+String mydbflutePath = introPhysicalLogic.buildMydbflutePath();%0A        try %7B%0A            Path mydbfluteDir = Paths.get(mydbflutePath);%0A            if (!mydbfluteDir.toFile().exists()) %7B%0A                return Collections.emptyList();%0A            %7D%0A            String enginePrefix = %22dbflute-%22;%0A            List%3CString%3E versionList = Files.list(mydbfluteDir)%0A                    .filter(file -%3E
  fil
@@ -1653,20 +1653,22 @@
 ith(
-%22dbflute-%22);
+enginePrefix))
 %0A   
@@ -1680,10 +1680,16 @@
     
-%7D)
+        
 .map
@@ -1735,11 +1735,52 @@
 ing(
-8))
+enginePrefix.length()))%0A                    
 .sor
@@ -1809,16 +1809,37 @@
 Order())
+%0A                    
 .collect
@@ -1880,17 +1880,24 @@
  return 
-l
+versionL
 ist;%0A   
@@ -1953,25 +1953,81 @@
 new 
-RuntimeException(
+IllegalStateException(%22Failed to get engine versions: %22 + mydbflutePath, 
 e);%0A

fix for non-existing mydbflute