1 | // FirstThread.java - Implementation of very first thread.
|
---|
2 |
|
---|
3 | /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
|
---|
4 |
|
---|
5 | This file is part of libgcj.
|
---|
6 |
|
---|
7 | This software is copyrighted work licensed under the terms of the
|
---|
8 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
---|
9 | details. */
|
---|
10 |
|
---|
11 | package gnu.gcj.runtime;
|
---|
12 |
|
---|
13 | import java.util.jar.*;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * @author Tom Tromey <tromey@cygnus.com>
|
---|
17 | * @date August 24, 1998
|
---|
18 | */
|
---|
19 |
|
---|
20 | final class FirstThread extends Thread
|
---|
21 | {
|
---|
22 | public FirstThread (Class k, String[] args)
|
---|
23 | {
|
---|
24 | super (null, null, "main");
|
---|
25 | klass = k;
|
---|
26 | this.args = args;
|
---|
27 | }
|
---|
28 |
|
---|
29 | public FirstThread (String class_name, String[] args, boolean is_jar)
|
---|
30 | {
|
---|
31 | super (null, null, "main");
|
---|
32 | klass_name = class_name;
|
---|
33 | this.args = args;
|
---|
34 | this.is_jar = is_jar;
|
---|
35 | }
|
---|
36 |
|
---|
37 | public void run()
|
---|
38 | {
|
---|
39 | if (is_jar)
|
---|
40 | klass_name = getMain(klass_name);
|
---|
41 |
|
---|
42 | if (klass == null)
|
---|
43 | {
|
---|
44 | try
|
---|
45 | {
|
---|
46 | klass = Class.forName(klass_name);
|
---|
47 | }
|
---|
48 | catch (ClassNotFoundException x)
|
---|
49 | {
|
---|
50 | throw new NoClassDefFoundError(klass_name);
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | call_main();
|
---|
55 | }
|
---|
56 |
|
---|
57 | private String getMain (String name)
|
---|
58 | {
|
---|
59 | String mainName = null;
|
---|
60 | try {
|
---|
61 |
|
---|
62 | JarFile j = new JarFile (name);
|
---|
63 |
|
---|
64 | Attributes a = j.getManifest().getMainAttributes();
|
---|
65 |
|
---|
66 | mainName = a.getValue(Attributes.Name.MAIN_CLASS);
|
---|
67 |
|
---|
68 | } catch (Exception e) {
|
---|
69 | // empty
|
---|
70 | }
|
---|
71 |
|
---|
72 | if (mainName == null)
|
---|
73 | {
|
---|
74 | System.err.println ("Failed to load Main-Class manifest attribute from\n"
|
---|
75 | + name);
|
---|
76 | System.exit(1);
|
---|
77 | }
|
---|
78 | return mainName;
|
---|
79 | }
|
---|
80 |
|
---|
81 | private native void call_main ();
|
---|
82 |
|
---|
83 | // Private data.
|
---|
84 | private Class klass;
|
---|
85 | private String klass_name;
|
---|
86 | private Object args;
|
---|
87 | private boolean is_jar;
|
---|
88 |
|
---|
89 | // If the user links statically then we need to ensure that these
|
---|
90 | // classes are linked in. Otherwise bootstrapping fails. These
|
---|
91 | // classes are only referred to via Class.forName(), so we add an
|
---|
92 | // explicit mention of them here.
|
---|
93 | static final Class Kcert = java.security.cert.Certificate.class;
|
---|
94 | static final Class Kfile = gnu.gcj.protocol.file.Handler.class;
|
---|
95 | static final Class Khttp = gnu.gcj.protocol.http.Handler.class;
|
---|
96 | static final Class Kjar = gnu.gcj.protocol.jar.Handler.class;
|
---|
97 | static final Class KinputASCII = gnu.gcj.convert.Input_ASCII.class;
|
---|
98 | static final Class KoutputASCII = gnu.gcj.convert.Output_ASCII.class;
|
---|
99 | }
|
---|