OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [gnu/] [java/] [lang/] [MainThread.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* gnu.java.lang.MainThread
2
   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3
   Free Software Foundation, Inc.
4
 
5
This file is part of GNU Classpath.
6
 
7
GNU Classpath is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2, or (at your option)
10
any later version.
11
 
12
GNU Classpath is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with GNU Classpath; see the file COPYING.  If not, write to the
19
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
02110-1301 USA.
21
 
22
Linking this library statically or dynamically with other modules is
23
making a combined work based on this library.  Thus, the terms and
24
conditions of the GNU General Public License cover the whole
25
combination.
26
 
27
As a special exception, the copyright holders of this library give you
28
permission to link this library with independent modules to produce an
29
executable, regardless of the license terms of these independent
30
modules, and to copy and distribute the resulting executable under
31
terms of your choice, provided that you also meet, for each linked
32
independent module, the terms and conditions of the license of that
33
module.  An independent module is a module which is not derived from
34
or based on this library.  If you modify this library, you may extend
35
this exception to your version of the library, but you are not
36
obligated to do so.  If you do not wish to do so, delete this
37
exception statement from your version. */
38
 
39
 
40
package gnu.java.lang;
41
 
42
import java.util.jar.Attributes;
43
import java.util.jar.JarFile;
44
 
45
/**
46
 * MainThread is a Thread which uses the main() method of some class.
47
 *
48
 * @author John Keiser
49
 * @author Tom Tromey (tromey@redhat.com)
50
 */
51
final class MainThread extends Thread
52
{
53
  // If the user links statically then we need to ensure that these
54
  // classes are linked in.  Otherwise bootstrapping fails.  These
55
  // classes are only referred to via Class.forName(), so we add an
56
  // explicit mention of them here.
57
  static final Class Kcert     = java.security.cert.Certificate.class;
58
  static final Class Kfile     = gnu.java.net.protocol.file.Handler.class;
59
  static final Class Khttp     = gnu.java.net.protocol.http.Handler.class;
60
  static final Class Kjar      = gnu.java.net.protocol.jar.Handler.class;
61
  static final Class Klocale   = gnu.java.locale.LocaleInformation.class;
62
  static final Class Kcalendar = gnu.java.locale.Calendar.class;
63
 
64
  // Private data.
65
  private Class klass;
66
  private String klass_name;
67
  private String[] args;
68
  private boolean is_jar;
69
 
70
  public MainThread(Class k, String[] args)
71
  {
72
    super(null, null, "main");
73
    klass = k;
74
    this.args = args;
75
  }
76
 
77
  public MainThread(String classname, String[] args, boolean is_jar)
78
  {
79
    super (null, null, "main");
80
    klass_name = classname;
81
    this.args = args;
82
    this.is_jar = is_jar;
83
  }
84
 
85
  public void run()
86
  {
87
    if (is_jar)
88
      klass_name = getMain(klass_name);
89
 
90
    if (klass == null)
91
      {
92
        try
93
          {
94
            klass = Class.forName(klass_name, true,
95
                                  ClassLoader.getSystemClassLoader());
96
          }
97
        catch (ClassNotFoundException x)
98
          {
99
            NoClassDefFoundError ncdfe = new NoClassDefFoundError(klass_name);
100
            ncdfe.initCause(x);
101
            throw ncdfe;
102
          }
103
      }
104
 
105
    call_main();
106
  }
107
 
108
  private String getMain(String name)
109
  {
110
    String mainName = null;
111
    try
112
      {
113
        JarFile j = new JarFile(name);
114
        Attributes a = j.getManifest().getMainAttributes();
115
        mainName = a.getValue(Attributes.Name.MAIN_CLASS);
116
      }
117
    catch (Exception e)
118
      {
119
        // Ignore.
120
      }
121
 
122
    if (mainName == null)
123
      {
124
        System.err.println("Failed to load Main-Class manifest attribute from "
125
                           + name);
126
        System.exit(1);
127
      }
128
    return mainName;
129
  }
130
 
131
  // Note: this function name is known to the stack tracing code.
132
  // You shouldn't change this without also updating stacktrace.cc.
133
  private native void call_main();
134
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.