/**
* (C) Copyright IBM Corporation 2016.
*
* 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 net.wasdev.maven.plugins.swaggerdocgen;

import java.io.File;

import org.apache.commons.io.FilenameUtils;


public class GenerateSwaggerFile {
    public static void main(String[] args) throws Exception {
        if(args.length == 1 || args.length == 2) {
            File warFile = handleFirstArgument(args[0]);
            if(warFile == null) {
                System.exit(1);
            }

            File outputFile;
            if(args.length == 1) {
                outputFile = handleSecondArgument(warFile,null);
            } else {
                outputFile = handleSecondArgument(warFile,args[1]);
            }

            if(outputFile == null) {
                System.exit(1);
            }

            SwaggerProcessor processor = new SwaggerProcessor(GenerateSwaggerFile.class.getClassLoader(), warFile, outputFile); 
            processor.process();
                
            System.out.println("Success: Your swagger file was succcessfully generated.");
            
            System.exit(0);
        }

        System.out.println("Please provide the path of the WAR application as an argument (and optionally the name of the swagger file)");
        System.exit(1);
    }


    /**
    * Handle the first argument.
    * Return WAR application as a file on success
    * Return null if failiure
    */
    private static File handleFirstArgument(String argument) {
        File warFile = new File(argument);
        if(warFile.exists()) {
            return warFile;
        }

        System.out.println("Error: The specified WAR application could not be found.");
        return null;
    }

    /**
    * Handle the second argument
    * Return output File object on success
    * Return null if failiure
    */
    private static File handleSecondArgument(File warFile, String argument) {
        File warFileDirectory = warFile.getAbsoluteFile().getParentFile();
        if(argument == null) {
            return new File(warFileDirectory.getPath() + File.separator + "swagger.yaml");
        }
        String ext = FilenameUtils.getExtension(argument);
        if(!(ext.equalsIgnoreCase("json") || ext.equalsIgnoreCase("yaml"))) {
            System.out.println("Please specify the extension type as json or yaml");
            return null;
        }
        File tempFile = new File(argument);
        if(tempFile.isAbsolute() && !tempFile.isDirectory()) {
            return tempFile;
        }

        return new File(warFileDirectory.getPath() + File.separator + argument);

    }
}

@@ -649,16 +649,49 @@
 io.File;
+%0Aimport java.util.logging.Logger;
 %0A%0Aimport
@@ -729,17 +729,16 @@
 Utils;%0A%0A
-%0A
 public c
@@ -760,24 +760,122 @@
 aggerFile %7B%0A
+%0A    private static final Logger logger = Logger.getLogger(GenerateSwaggerFile.class.getName());%0A%0A
     public s
@@ -1002,35 +1002,29 @@
 rFile = 
-handleFirstArgument
+createWARFile
 (args%5B0%5D
@@ -1200,36 +1200,32 @@
 tFile = 
-handleSecondArgument
+createOutputFile
 (warFile
@@ -1225,16 +1225,17 @@
 warFile,
+ 
 null);%0A 
@@ -1283,36 +1283,32 @@
 tFile = 
-handleSecondArgument
+createOutputFile
 (warFile
@@ -1308,16 +1308,17 @@
 warFile,
+ 
 args%5B1%5D)
@@ -1609,34 +1609,27 @@
         
-System.out.println
+logger.info
 (%22Succes
@@ -1741,34 +1741,29 @@
         
-System.out.println
+logger.severe
 (%22Please
@@ -2055,27 +2055,21 @@
 ile 
-handleFirstArgument
+createWARFile
 (Str
@@ -2205,34 +2205,29 @@
         
-System.out.println
+logger.severe
 (%22Error:
@@ -2457,28 +2457,24 @@
 ile 
-handleSecondArgument
+createOutputFile
 (Fil
@@ -2863,26 +2863,21 @@
     
-System.out.println
+logger.severe
 (%22Pl

change to logger