// Copyright © 2013 Esko Luontola <www.orfjackal.net>
// This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0

package net.orfjackal.retrolambda;

import java.io.*;
import java.nio.file.*;
import java.util.Properties;

public class Main {

    public static void main(String[] args) {
        System.out.println("Retrolambda " + getVersion());

        Config config = new Config(System.getProperties());
        Path inputDir = config.getInputDir();
        Path outputDir = config.getOutputDir();

        if (!Files.isDirectory(inputDir)) {
            System.out.println("Nothing to do; not a directory: " + inputDir);
            return;
        }

        try {
            Files.walkFileTree(inputDir, new BytecodeTransformingFileVisitor(inputDir, outputDir) {
                protected byte[] transform(byte[] bytecode) {
                    return LambdaUsageBackporter.transform(bytecode);
                }
            });

        } catch (Throwable t) {
            System.out.println("Error! Failed to transform some classes");
            t.printStackTrace(System.out);
            System.exit(1);
        }
    }

    private static String getVersion() {
        Properties p = new Properties();
        try (InputStream in = ClassLoader.getSystemResourceAsStream("META-INF/maven/net.orfjackal.retrolambda/retrolambda/pom.properties")) {
            if (in != null) {
                p.load(in);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return p.getProperty("version", "DEVELOPMENT-VERSION");
    }
}

@@ -563,16 +563,139 @@
 utDir();
+%0A        System.out.println(%22Input directory:  %22 + inputDir);%0A        System.out.println(%22Output directory: %22 + outputDir);
 %0A%0A      

Print configuration on startup