aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/glavo/javah/Main.java
blob: 6df9539e1dbf1fbf1e506371e7432a2d2aa83652 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package org.glavo.javah;

import java.io.InputStream;
import java.nio.file.Paths;
import java.util.jar.Manifest;

public class Main {
    private static final String HELP_MESSAGE =
            "usage:\n" +
                    "  gjavah [options] <classes>\n" +
                    "where [options] include:\n" +
                    "    -o <file>                       Output file (only one of -d or -o may be used)\n" +
                    "    -d <dir>                        Output directory\n" +
                    "    --module-path <path>            Path from which to search  modules\n" +
                    "    --class-path <path> | " +
                    "-classpath <path> | -cp <path>\n" +
                    "                                    " +
                    "                                Path from which to search classes\n" +
                    "    --version                       Print version information\n" +
                    "    -h  --help  -?                  Print this message";

    public static void main(String[] args) throws Exception {
        if (args.length == 0) {
            System.err.println(HELP_MESSAGE);
            System.exit(-1);
        }
        JavahTask task = new JavahTask();
        task.addRuntimeClasspath();
        loop:
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            switch (arg) {
                case "--version":
                case "-version":
                    try (InputStream in = Main.class.getResourceAsStream("/META-INF/MANIFEST.MF")) {
                        Manifest manifest = new Manifest(in);
                        System.out.println("gjavah version: " + manifest.getMainAttributes().getValue("GJavah-Version"));
                    }
                    return;
                case "-h":
                case "--help":
                case "-help":
                case "-?":
                    System.out.println(HELP_MESSAGE);
                    return;
                case "-o":
                    task.setOutputToSignalFile(true);
                    task.setOutputPath(Paths.get(args[++i]));
                    break;
                case "-d":
                    task.setOutputToSignalFile(false);
                    task.setOutputPath(Paths.get(args[++i]));
                    break;
                case "--module-path":
                    task.addModulePaths(args[++i]);
                    break;
                case "--class-path":
                case "--classpath":
                case "-classpath":
                case "-cp":
                    task.addClasspaths(args[++i]);
                    break;
                default:
                    while (i < args.length) {
                        task.addClass(args[i++]);
                    }
            }
        }
        task.run();
    }
}