<commit_before>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2009 INRIA/University of Nice-Sophia Antipolis
 * Contact: <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://proactive.inria.fr/team_members.htm
 *  Contributor(s):
 *
 * ################################################################
 * $$PROACTIVE_INITIAL_DEV$$
 */
package org.objectweb.proactive.ext.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;

import javassist.ClassClassPath;
import javassist.ClassPool;

import org.objectweb.proactive.core.mop.JavassistByteCodeStubBuilder;
import org.objectweb.proactive.core.mop.Utils;


public class StubGenerator {
    public static void main(String[] args) {
        StubGenerator sg = new StubGenerator(args);
        sg.run();
    }

    private File srcDir;
    private String pkg = "";
    private File destDir;
    private String cl;
    private boolean verbose = false;

    public StubGenerator(String[] args) {
        ClassPool pool = ClassPool.getDefault();
        pool.insertClassPath(new ClassClassPath(this.getClass()));

        int index = 0;
        while (index < args.length) {
            if (args[index].equals("-srcDir")) {
                srcDir = new File(args[index + 1]);
                index += 2;
            } else if (args[index].equals("-pkg")) {
                pkg = args[index + 1];
                index += 2;
            } else if (args[index].equals("-destDir")) {
                destDir = new File(args[index + 1]);
                index += 2;
            } else if (args[index].equals("-class")) {
                cl = args[index + 1];
                index += 2;
            } else if (args[index].equals("-verbose")) {
                verbose = true;
                index++;
            } else {
                usage();
                System.exit(1);
            }
        }
    }

    public void usage() {
        System.out.println("Usage:");
        System.out.println("\t-srcDir  directory where to find source classes");
        System.out.println("\t-destDir directory where to put generated stubs");
        System.out.println("\t-pkg     package name");
        System.out.println("\t-class   generate only a stub for this class");
        System.out.println("\t-verbose enable verbose mode");
        System.out.println("");
    }

    public void logAndExit(String str) {
        System.err.println(str);
        System.exit(2);
    }

    public void run() {
        if (srcDir == null) {
            logAndExit("srcDir attribute is not set");
        }
        if (!srcDir.exists()) {
            logAndExit("Invalid srcDir attribute: " + srcDir.toString() + " does not exist");
        }
        if (!srcDir.isDirectory()) {
            logAndExit("Invalid srcDir attribute: " + srcDir.toString() + " is not a directory");
        }

        if (pkg == null) {
            logAndExit("pkg attribute is not set");
        }
        File pkgDir = new File(srcDir.toString() + File.separator + pkg.replace('.', File.separatorChar));
        if (!pkgDir.exists()) {
            logAndExit("Invalid pkg attribute: " + pkgDir.toString() + " does not exist");
        }

        if (destDir == null) {
            destDir = srcDir;
        }
        if (!destDir.isDirectory()) {
            logAndExit("Invalid dest attribute: " + destDir.toString() + " is not a directory");
        }
        if (!destDir.isDirectory()) {
            logAndExit("Invalid src attribute: " + destDir.toString() + " is not a directory");
        }

        List<File> files = new ArrayList<File>();

        if (cl == null) {
            // Find all the classes in this package
            files.addAll(exploreDirectory(pkgDir));
        } else {
            File file = new File(pkgDir + File.separator + cl + ".class");
            if (!file.exists() || !file.isFile()) {
                logAndExit("Invalid pkg or class attribute: " + file.toString() + " does not exist");
            }

            files.add(file);
        }

        PrintStream stderr = System.err;
        PrintStream mute = new PrintStream(new MuteOutputStream());

        if (!verbose) {
            System.setErr(mute);
        }

        // ClassPool.releaseUnmodifiedClassFile = true;
        for (File file : files) {
            String str = file.toString().replaceFirst(Matcher.quoteReplacement(srcDir.toString()), "");

                if (!verbose) {
                    System.setErr(mute);
                }

                boolean success = StubGenerator.generateClass(str, destDir.toString() + File.separator);
                if (success) {
                    System.out.println("Generated stub: " +
                        Utils.convertClassNameToStubClassName(processClassName(str), null));
                }
        }
<commit_msg>format PROACTIVE-685<commit_after>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2009 INRIA/University of Nice-Sophia Antipolis
 * Contact: <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://proactive.inria.fr/team_members.htm
 *  Contributor(s):
 *
 * ################################################################
 * $$PROACTIVE_INITIAL_DEV$$
 */
package org.objectweb.proactive.ext.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;

import javassist.ClassClassPath;
import javassist.ClassPool;

import org.objectweb.proactive.core.mop.JavassistByteCodeStubBuilder;
import org.objectweb.proactive.core.mop.Utils;


public class StubGenerator {
    public static void main(String[] args) {
        StubGenerator sg = new StubGenerator(args);
        sg.run();
    }

    private File srcDir;
    private String pkg = "";
    private File destDir;
    private String cl;
    private boolean verbose = false;

    public StubGenerator(String[] args) {
        ClassPool pool = ClassPool.getDefault();
        pool.insertClassPath(new ClassClassPath(this.getClass()));

        int index = 0;
        while (index < args.length) {
            if (args[index].equals("-srcDir")) {
                srcDir = new File(args[index + 1]);
                index += 2;
            } else if (args[index].equals("-pkg")) {
                pkg = args[index + 1];
                index += 2;
            } else if (args[index].equals("-destDir")) {
                destDir = new File(args[index + 1]);
                index += 2;
            } else if (args[index].equals("-class")) {
                cl = args[index + 1];
                index += 2;
            } else if (args[index].equals("-verbose")) {
                verbose = true;
                index++;
            } else {
                usage();
                System.exit(1);
            }
        }
    }

    public void usage() {
        System.out.println("Usage:");
        System.out.println("\t-srcDir  directory where to find source classes");
        System.out.println("\t-destDir directory where to put generated stubs");
        System.out.println("\t-pkg     package name");
        System.out.println("\t-class   generate only a stub for this class");
        System.out.println("\t-verbose enable verbose mode");
        System.out.println("");
    }

    public void logAndExit(String str) {
        System.err.println(str);
        System.exit(2);
    }

    public void run() {
        if (srcDir == null) {
            logAndExit("srcDir attribute is not set");
        }
        if (!srcDir.exists()) {
            logAndExit("Invalid srcDir attribute: " + srcDir.toString() + " does not exist");
        }
        if (!srcDir.isDirectory()) {
            logAndExit("Invalid srcDir attribute: " + srcDir.toString() + " is not a directory");
        }

        if (pkg == null) {
            logAndExit("pkg attribute is not set");
        }
        File pkgDir = new File(srcDir.toString() + File.separator + pkg.replace('.', File.separatorChar));
        if (!pkgDir.exists()) {
            logAndExit("Invalid pkg attribute: " + pkgDir.toString() + " does not exist");
        }

        if (destDir == null) {
            destDir = srcDir;
        }
        if (!destDir.isDirectory()) {
            logAndExit("Invalid dest attribute: " + destDir.toString() + " is not a directory");
        }
        if (!destDir.isDirectory()) {
            logAndExit("Invalid src attribute: " + destDir.toString() + " is not a directory");
        }

        List<File> files = new ArrayList<File>();

        if (cl == null) {
            // Find all the classes in this package
            files.addAll(exploreDirectory(pkgDir));
        } else {
            File file = new File(pkgDir + File.separator + cl + ".class");
            if (!file.exists() || !file.isFile()) {
                logAndExit("Invalid pkg or class attribute: " + file.toString() + " does not exist");
            }

            files.add(file);
        }

        PrintStream stderr = System.err;
        PrintStream mute = new PrintStream(new MuteOutputStream());

        if (!verbose) {
            System.setErr(mute);
        }

        // ClassPool.releaseUnmodifiedClassFile = true;
        for (File file : files) {
            String str = file.toString().replaceFirst(Matcher.quoteReplacement(srcDir.toString()), "");

            if (!verbose) {
                System.setErr(mute);
            }

            boolean success = StubGenerator.generateClass(str, destDir.toString() + File.separator);
            if (success) {
                System.out.println("Generated stub: " +
                    Utils.convertClassNameToStubClassName(processClassName(str), null));
            }
        }

{'fraction_non_alphanumeric': 0.13684748360725538, 'fraction_numerical': 0.006046155156263306, 'mean_word_length': 2.1544453397797474, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3434053', 'n_tokens_mistral': 3238, 'n_tokens_neox': 3067, 'n_words': 883}