jdk/src/jdk.rmic/share/classes/sun/rmi/rmic/Main.java
author amlu
Tue, 10 Feb 2015 12:28:02 -0500
changeset 28856 1c525c8d1cf7
parent 27565 729f9700483a
child 43812 a6e3407e9f32
permissions -rw-r--r--
8069255: Suppress deprecation warnings in jdk.rmic module (jdk repo) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
28856
1c525c8d1cf7 8069255: Suppress deprecation warnings in jdk.rmic module (jdk repo)
amlu
parents: 27565
diff changeset
     2
 * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * Licensed Materials - Property of IBM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * RMI-IIOP v1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
package sun.rmi.rmic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.io.FileOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.io.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.tools.java.ClassFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.tools.java.ClassDefinition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.tools.java.ClassDeclaration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.tools.java.ClassNotFound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.tools.java.Identifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.tools.java.ClassPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.tools.javac.SourceClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.tools.util.CommandLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.lang.reflect.Constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Main "rmic" program.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * WARNING: The contents of this source file are not part of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * supported API.  Code that depends on them does so at its own risk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * they are subject to change or removal without notice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
public class Main implements sun.rmi.rmic.Constants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    String sourcePathArg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    String sysClassPathArg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    String classPathString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    File destDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    int flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    long tm;
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
    75
    Vector<String> classes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    boolean nowrite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    boolean nocompile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    boolean keepGenerated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    boolean status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    String[] generatorArgs;
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
    81
    Vector<Generator> generators;
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
    82
    Class<? extends BatchEnvironment> environmentClass =
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
    83
        BatchEnvironment.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    boolean iiopGeneration = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Name of the program.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    String program;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * The stream where error message are printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    OutputStream out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public Main(OutputStream out, String program) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.out = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.program = program;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Output a message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public void output(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        PrintStream out =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            this.out instanceof PrintStream ? (PrintStream)this.out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            : new PrintStream(this.out, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        out.println(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Top level error message.  This method is called when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * environment could not be set up yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public void error(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        output(getText(msg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public void error(String msg, String arg1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        output(getText(msg, arg1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public void error(String msg, String arg1, String arg2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        output(getText(msg, arg1, arg2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public void usage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        error("rmic.usage", program);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Run the compiler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public synchronized boolean compile(String argv[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         * Handle internal option to use the new (and incomplete) rmic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * implementation.  This option is handled here, rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         * in parseArgs, so that none of the arguments will be nulled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * before delegating to the new implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        for (int i = 0; i < argv.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            if (argv[i].equals("-Xnew")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                return (new sun.rmi.rmic.newrmic.Main(out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                                      program)).compile(argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (!parseArgs(argv)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (classes.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
22084
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   164
        if ((flags & F_WARNINGS) != 0) {
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   165
            for (Generator g : generators) {
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   166
                if (g instanceof RMIGenerator) {
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   167
                    output(getText("rmic.jrmp.stubs.deprecated", program));
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   168
                    break;
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   169
                }
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   170
            }
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   171
        }
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   172
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return doCompile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Get the destination directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public File getDestinationDir() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return destDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Parse the arguments for compile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public boolean parseArgs(String argv[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        sourcePathArg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        sysClassPathArg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        classPathString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        destDir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        flags = F_WARNINGS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        tm = System.currentTimeMillis();
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   194
        classes = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        nowrite = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        nocompile = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        keepGenerated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        generatorArgs = getArray("generator.args",true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (generatorArgs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   202
        generators = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // Pre-process command line for @file arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            argv = CommandLine.parse(argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            error("rmic.cant.read", e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            e.printStackTrace(out instanceof PrintStream ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                              (PrintStream) out :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                              new PrintStream(out, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // Parse arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        for (int i = 0 ; i < argv.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            if (argv[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                if (argv[i].equals("-g")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    flags &= ~F_OPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    flags |= F_DEBUG_LINES | F_DEBUG_VARS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                } else if (argv[i].equals("-O")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    flags &= ~F_DEBUG_LINES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    flags &= ~F_DEBUG_VARS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    flags |= F_OPT | F_DEPENDENCIES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                } else if (argv[i].equals("-nowarn")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    flags &= ~F_WARNINGS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                } else if (argv[i].equals("-debug")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    flags |= F_DUMP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                } else if (argv[i].equals("-depend")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    flags |= F_DEPENDENCIES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                } else if (argv[i].equals("-verbose")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    flags |= F_VERBOSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                } else if (argv[i].equals("-nowrite")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    nowrite = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                } else if (argv[i].equals("-Xnocompile")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    nocompile = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    keepGenerated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                } else if (argv[i].equals("-keep") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                           argv[i].equals("-keepgenerated")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    keepGenerated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                } else if (argv[i].equals("-show")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    error("rmic.option.unsupported", "-show");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                    usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                } else if (argv[i].equals("-classpath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    if ((i + 1) < argv.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        if (classPathString != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                            error("rmic.option.already.seen", "-classpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        classPathString = argv[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                        error("rmic.option.requires.argument", "-classpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                } else if (argv[i].equals("-sourcepath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    if ((i + 1) < argv.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                        if (sourcePathArg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                            error("rmic.option.already.seen", "-sourcepath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        sourcePathArg = argv[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                        error("rmic.option.requires.argument", "-sourcepath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                } else if (argv[i].equals("-bootclasspath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    if ((i + 1) < argv.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                        if (sysClassPathArg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                            error("rmic.option.already.seen", "-bootclasspath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        sysClassPathArg = argv[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        error("rmic.option.requires.argument", "-bootclasspath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                } else if (argv[i].equals("-d")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    if ((i + 1) < argv.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        if (destDir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                            error("rmic.option.already.seen", "-d");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                        destDir = new File(argv[++i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        if (!destDir.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                            error("rmic.no.such.directory", destDir.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                        error("rmic.option.requires.argument", "-d");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    if (!checkGeneratorArg(argv,i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        // Now that all generators have had a chance at the args,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        // scan what's left for classes and illegal args...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        for (int i = 0; i < argv.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            if (argv[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                if (argv[i].startsWith("-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    error("rmic.no.such.option", argv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    classes.addElement(argv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        // If the generators vector is empty, add the default generator...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (generators.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            addGenerator("default");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * If this argument is for a generator, instantiate it, call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * parseArgs(...) and add generator to generators vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Returns false on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    protected boolean checkGeneratorArg(String[] argv, int currentIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        boolean result = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (argv[currentIndex].startsWith("-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            String arg = argv[currentIndex].substring(1).toLowerCase(); // Remove '-'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            for (int i = 0; i < generatorArgs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                if (arg.equalsIgnoreCase(generatorArgs[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    // Got a match, add Generator and call parseArgs...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    Generator gen = addGenerator(arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    if (gen == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    result = gen.parseArgs(argv,this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * Instantiate and add a generator to the generators array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    protected Generator addGenerator(String arg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        Generator gen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        // Create an instance of the generator and add it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        // the array...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        String className = getString("generator.class." + arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        if (className == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            error("rmic.missing.property",arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            gen = (Generator) Class.forName(className).newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            error("rmic.cannot.instantiate",className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        generators.addElement(gen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        // Get the environment required by this generator...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   407
        Class<?> envClass = BatchEnvironment.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        String env = getString("generator.env." + arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        if (env != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                envClass = Class.forName(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                // Is the new class a subclass of the current one?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                if (environmentClass.isAssignableFrom(envClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    // Yes, so switch to the new one...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   419
                    environmentClass = envClass.asSubclass(BatchEnvironment.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    // No. Is the current class a subclass of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    // new one?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    if (!envClass.isAssignableFrom(environmentClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                        // No, so it's a conflict...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        error("rmic.cannot.use.both",environmentClass.getName(),envClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                error("rmic.class.not.found",env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        // If this is the iiop stub generator, cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        // that fact for the jrmp generator...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        if (arg.equals("iiop")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            iiopGeneration = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        return gen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Grab a resource string and parse it into an array of strings. Assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * comma separated list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @param name The resource name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @param mustExist If true, throws error if resource does not exist. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * false and resource does not exist, returns zero element array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    protected String[] getArray(String name, boolean mustExist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        String[] result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        String value = getString(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            if (mustExist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                error("rmic.resource.not.found",name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                return new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        StringTokenizer parser = new StringTokenizer(value,", \t\n\r", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        int count = parser.countTokens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        result = new String[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            result[i] = parser.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * Get the correct type of BatchEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public BatchEnvironment getEnv() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        ClassPath classPath =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            BatchEnvironment.createClassPath(classPathString,
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   485
                                             sysClassPathArg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        BatchEnvironment result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        try {
21655
55f32ae4f920 8028229: Fix more raw types lint warning in core libraries
darcy
parents: 18137
diff changeset
   488
            Class<?>[] ctorArgTypes = {OutputStream.class,ClassPath.class,Main.class};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            Object[] ctorArgs = {out,classPath,this};
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   490
            Constructor<? extends BatchEnvironment> constructor =
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   491
                environmentClass.getConstructor(ctorArgTypes);
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   492
            result =  constructor.newInstance(ctorArgs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            result.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            error("rmic.cannot.instantiate",environmentClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Do the compile with the switches and files already supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public boolean doCompile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        // Create batch environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        BatchEnvironment env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        env.flags |= flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        // Set the classfile version numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        // Compat and 1.1 stubs must retain the old version number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        env.majorVersion = 45;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        env.minorVersion = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        // Preload the "out of memory" error string just in case we run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        // out of memory during the compile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        String noMemoryErrorString = getText("rmic.no.memory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        String stackOverflowErrorString = getText("rmic.stack.overflow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            /** Load the classes on the command line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
             * Replace the entries in classes with the ClassDefinition for the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            for (int i = classes.size()-1; i >= 0; i-- ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                Identifier implClassName =
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   526
                    Identifier.lookup(classes.elementAt(i));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                 * Fix bugid 4049354: support using '.' as an inner class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                 * qualifier on the command line (previously, only mangled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                 * inner class names were understood, like "pkg.Outer$Inner").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                 * The following method, also used by "javap", resolves the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                 * given unmangled inner class name to the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                 * internal identifier.  For example, it translates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                 * "pkg.Outer.Inner" to "pkg.Outer. Inner".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                implClassName = env.resolvePackageQualifiedName(implClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                 * But if we use such an internal inner class name identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                 * to load the class definition, the Java compiler will notice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                 * if the impl class is a "private" inner class and then deny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                 * skeletons (needed unless "-v1.2" is used) the ability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                 * cast to it.  To work around this problem, we mangle inner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                 * class name identifiers to their binary "outer" class name:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                 * "pkg.Outer. Inner" becomes "pkg.Outer$Inner".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                implClassName = Names.mangleClass(implClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                ClassDeclaration decl = env.getClassDeclaration(implClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    ClassDefinition def = decl.getClassDefinition(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    for (int j = 0; j < generators.size(); j++) {
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   554
                        Generator gen = generators.elementAt(j);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                        gen.generate(env, def, destDir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                } catch (ClassNotFound ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    env.error(0, "rmic.class.not.found", implClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            // compile all classes that need compilation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            if (!nocompile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                compileAllClasses(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        } catch (OutOfMemoryError ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            // The compiler has run out of memory.  Use the error string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            // which we preloaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            env.output(noMemoryErrorString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        } catch (StackOverflowError ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            env.output(stackOverflowErrorString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        } catch (Error ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            // We allow the compiler to take an exception silently if a program
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            // error has previously been detected.  Presumably, this makes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            // compiler more robust in the face of bad error recovery.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            if (env.nerrors == 0 || env.dump()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                env.error(0, "fatal.error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                ee.printStackTrace(out instanceof PrintStream ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                   (PrintStream) out :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                   new PrintStream(out, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        } catch (Exception ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            if (env.nerrors == 0 || env.dump()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                env.error(0, "fatal.exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                ee.printStackTrace(out instanceof PrintStream ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                                   (PrintStream) out :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                                   new PrintStream(out, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        env.flushErrors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        boolean status = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if (env.nerrors > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            String msg = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            if (env.nerrors > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                msg = getText("rmic.errors", env.nerrors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                msg = getText("rmic.1error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            if (env.nwarnings > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                if (env.nwarnings > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    msg += ", " + getText("rmic.warnings", env.nwarnings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    msg += ", " + getText("rmic.1warning");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            output(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            status = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (env.nwarnings > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                if (env.nwarnings > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    output(getText("rmic.warnings", env.nwarnings));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    output(getText("rmic.1warning"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        // last step is to delete generated source files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (!keepGenerated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            env.deleteGeneratedFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        // We're done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        if (env.verbose()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            tm = System.currentTimeMillis() - tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            output(getText("rmic.done_in", Long.toString(tm)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        // Shutdown the environment object and release our resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        // Note that while this is unneccessary when rmic is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        // the command line, there are environments in which rmic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        // from is invoked within a server process, so resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        // reclamation is important...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        env.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        sourcePathArg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        sysClassPathArg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        classPathString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        destDir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        classes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        generatorArgs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        generators = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        environmentClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        program = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        out = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * Compile all classes that need to be compiled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    public void compileAllClasses (BatchEnvironment env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        throws ClassNotFound,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
               IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
               InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        boolean done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            done = true;
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   668
            for (Enumeration<?> e = env.getClasses() ; e.hasMoreElements() ; ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                ClassDeclaration c = (ClassDeclaration)e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                done = compileClass(c,buf,env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        } while (!done);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * Compile a single class.
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   677
     * Fallthrough is intentional
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     */
28856
1c525c8d1cf7 8069255: Suppress deprecation warnings in jdk.rmic module (jdk repo)
amlu
parents: 27565
diff changeset
   679
    @SuppressWarnings({"fallthrough", "deprecation"})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    public boolean compileClass (ClassDeclaration c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                                 ByteArrayOutputStream buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                                 BatchEnvironment env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        throws ClassNotFound,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
               IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
               InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        boolean done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        env.flushErrors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        SourceClass src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        switch (c.getStatus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        case CS_UNDEFINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                if (!env.dependencies()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                // fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        case CS_SOURCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                env.loadDefinition(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                if (c.getStatus() != CS_PARSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                // fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        case CS_PARSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                if (c.getClassDefinition().isInsideLocal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                // If we get to here, then compilation is going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                // to occur. If the -Xnocompile switch is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                // then fail. Note that this check is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                // here because this method is called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                // generators, not just from within this class...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                if (nocompile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                    throw new IOException("Compilation required, but -Xnocompile option in effect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                src = (SourceClass)c.getClassDefinition(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                src.check(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                c.setDefinition(src, CS_CHECKED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                // fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        case CS_CHECKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                src = (SourceClass)c.getClassDefinition(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                // bail out if there were any errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                if (src.getError()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                    c.setDefinition(src, CS_COMPILED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                buf.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                src.compile(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                c.setDefinition(src, CS_COMPILED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                src.cleanup(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                if (src.getError() || nowrite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                String pkgName = c.getName().getQualifier().toString().replace('.', File.separatorChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                String className = c.getName().getFlatName().toString().replace('.', SIGC_INNERCLASS) + ".class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                File file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                if (destDir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                    if (pkgName.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                        file = new File(destDir, pkgName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                        if (!file.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                            file.mkdirs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                        file = new File(file, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                        file = new File(destDir, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                    ClassFile classfile = (ClassFile)src.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                    if (classfile.isZipped()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                        env.error(0, "cant.write", classfile.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                    file = new File(classfile.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                    file = new File(file.getParent(), className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                // Create the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    FileOutputStream out = new FileOutputStream(file.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    buf.writeTo(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                    if (env.verbose()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                        output(getText("rmic.wrote", file.getPath()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                } catch (IOException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                    env.error(0, "cant.write", file.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        return done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * Main program
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    public static void main(String argv[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        Main compiler = new Main(System.out, "rmic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        System.exit(compiler.compile(argv) ? 0 : 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * Return the string value of a named resource in the rmic.properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * resource bundle.  If the resource is not found, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    public static String getString(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        if (!resourcesInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            initResources();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        // To enable extensions, search the 'resourcesExt'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        // bundle first, followed by the 'resources' bundle...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        if (resourcesExt != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                return resourcesExt.getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            } catch (MissingResourceException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            return resources.getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        } catch (MissingResourceException ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    private static boolean resourcesInitialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    private static ResourceBundle resources;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    private static ResourceBundle resourcesExt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    private static void initResources() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            resources =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                ResourceBundle.getBundle("sun.rmi.rmic.resources.rmic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            resourcesInitialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                resourcesExt =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                    ResourceBundle.getBundle("sun.rmi.rmic.resources.rmicext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            } catch (MissingResourceException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        } catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            throw new Error("fatal: missing resource bundle: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                            e.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    public static String getText(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        String message = getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        if (message == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            message = "no text found: \"" + key + "\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        return message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    public static String getText(String key, int num) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        return getText(key, Integer.toString(num), null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    public static String getText(String key, String arg0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        return getText(key, arg0, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    public static String getText(String key, String arg0, String arg1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        return getText(key, arg0, arg1, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public static String getText(String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                                 String arg0, String arg1, String arg2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        String format = getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        if (format == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            format = "no text found: key = \"" + key + "\", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                "arguments = \"{0}\", \"{1}\", \"{2}\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        String[] args = new String[3];
18137
264000e285e9 8015470: Remove redundant calls of toString() on String objects
dholmes
parents: 14342
diff changeset
   872
        args[0] = (arg0 != null ? arg0 : "null");
264000e285e9 8015470: Remove redundant calls of toString() on String objects
dholmes
parents: 14342
diff changeset
   873
        args[1] = (arg1 != null ? arg1 : "null");
264000e285e9 8015470: Remove redundant calls of toString() on String objects
dholmes
parents: 14342
diff changeset
   874
        args[2] = (arg2 != null ? arg2 : "null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   876
        return java.text.MessageFormat.format(format, (Object[]) args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
}