package blanco.nlpack.generator.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

/**
 * 
 * @author iga
 * @deprecated 結局利用されなくなりました。
 */
public class BlancoEclipseBabelExpandForLargeContribution {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(final String[] args) throws IOException {
        final BufferedWriter writer = new BufferedWriter(new FileWriter(
                "./tmp/build.xml.part"));
        try {
            writer.write("        <!-- " + new Date().toString() + " -->");
            writer.newLine();
            process(new File("./tmp/phase1.nlexpand/eclipse/features"), writer);
            process(new File("./tmp/phase1.nlexpand/eclipse/plugins"), writer);
        } finally {
            writer.close();
        }
    }

    public static void process(final File targetDir, final BufferedWriter writer)
            throws IOException {
        final File[] files = targetDir.listFiles();
        if (files == null) {
            throw new IllegalArgumentException("ディレクトリ["
                    + targetDir.getAbsolutePath() + "]が見つかりません");
        }

        for (int index = 0; index < files.length; index++) {
            if (files[index].isFile() == false) {
                continue;
            }
            int nl_ja = files[index].getName().indexOf(".nl_ja");
            if (nl_ja < 0) {
                continue;
            }
            final String targetSubDir = files[index].getName().substring(0,
                    nl_ja);
            final String targetSubDirFull = "./tmp/phase2.babel/ja/eclipse/"
                    + targetDir.getName() + "/" + targetSubDir;

            writer.write("        <unzip src=\"./tmp/phase1.nlexpand/eclipse/"
                    + targetDir.getName() + "/" + files[index].getName()
                    + ".jar\" dest=\"" + targetSubDirFull + "\" />");
            writer.newLine();
        }

        for (int index = 0; index < files.length; index++) {
            if (files[index].isFile() == false) {
                continue;
            }
            int nl_ja = files[index].getName().indexOf(".nl_ja");
            if (nl_ja < 0) {
                continue;
            }
            final String targetSubDir = files[index].getName().substring(0,
                    nl_ja);
            final String targetSubDirFull = "./tmp/phase2.babel/ja/eclipse/"
                    + targetDir.getName() + "/" + targetSubDir;

            writer.write("        <delete dir=\"" + targetSubDirFull
                    + "/META-INF\" />");
            writer.newLine();
            writer.write("        <delete file=\"" + targetSubDirFull
                    + "/nl_fragment.properties\" />");
            writer.newLine();
        }
    }
}
