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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [gnu/] [java/] [lang/] [MainThread.java] - Blame information for rev 756

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 756 jeremybenn
/* gnu.java.lang.MainThread
2
   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3
   2006, 2008 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.io.File;
43
import java.util.jar.Attributes;
44
import java.util.jar.JarFile;
45
 
46
/**
47
 * MainThread is a Thread which uses the main() method of some class.
48
 *
49
 * @author John Keiser
50
 * @author Tom Tromey (tromey@redhat.com)
51
 */
52
final class MainThread extends Thread
53
{
54
  // If the user links statically then we need to ensure that these
55
  // classes are linked in.  Otherwise bootstrapping fails.  These
56
  // classes are only referred to via Class.forName(), so we add an
57
  // explicit mention of them here.
58
  static final Class Kcert     = java.security.cert.Certificate.class;
59
  static final Class Kfile     = gnu.java.net.protocol.file.Handler.class;
60
  static final Class Khttp     = gnu.java.net.protocol.http.Handler.class;
61
  static final Class Kjar      = gnu.java.net.protocol.jar.Handler.class;
62
 
63
  // Private data.
64
  private Class klass;
65
  private String klass_name;
66
  private String[] args;
67
  private boolean is_jar;
68
 
69
  public MainThread(Class k, String[] args)
70
  {
71
    super(null, null, "main");
72
    klass = k;
73
    this.args = args;
74
  }
75
 
76
  public MainThread(String classname, String[] args, boolean is_jar)
77
  {
78
    super (null, null, "main");
79
    klass_name = classname;
80
    this.args = args;
81
    this.is_jar = is_jar;
82
  }
83
 
84
  public void run()
85
  {
86
    if (is_jar)
87
      klass_name = getMain(klass_name);
88
 
89
    if (klass == null)
90
      {
91
        try
92
          {
93
            ClassLoader cl = ClassLoader.getSystemClassLoader();
94
            // Permit main class name to be specified in file-system format.
95
            klass_name = klass_name.replace(File.separatorChar, '.');
96
            klass = cl.loadClass(klass_name);
97
          }
98
        catch (ClassNotFoundException x)
99
          {
100
            NoClassDefFoundError ncdfe = new NoClassDefFoundError(klass_name);
101
            ncdfe.initCause(x);
102
            throw ncdfe;
103
          }
104
      }
105
 
106
    call_main();
107
  }
108
 
109
  private String getMain(String name)
110
  {
111
    String mainName = null;
112
    try
113
      {
114
        JarFile j = new JarFile(name);
115
        Attributes a = j.getManifest().getMainAttributes();
116
        mainName = a.getValue(Attributes.Name.MAIN_CLASS);
117
      }
118
    catch (Exception e)
119
      {
120
        // Ignore.
121
      }
122
 
123
    if (mainName == null)
124
      {
125
        System.err.println("Failed to load Main-Class manifest attribute from "
126
                           + name);
127
        System.exit(1);
128
      }
129
    return mainName;
130
  }
131
 
132
  // Note: this function name is known to the stack tracing code.
133
  // You shouldn't change this without also updating stacktrace.cc.
134
  private native void call_main();
135
}

powered by: WebSVN 2.1.0

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