src/jdk.rmic/share/classes/sun/rmi/rmic/Main.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 43812 jdk/src/jdk.rmic/share/classes/sun/rmi/rmic/Main.java@a6e3407e9f32
child 47493 843c071258a6
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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
         */
43812
a6e3407e9f32 8146299: Disable rmic -Xnew
msheppar
parents: 28856
diff changeset
   148
        // disable the -Xnew option as per JDK-8146299 and JDK-8145980
a6e3407e9f32 8146299: Disable rmic -Xnew
msheppar
parents: 28856
diff changeset
   149
        // to allow further discussion how to progress with this feature
a6e3407e9f32 8146299: Disable rmic -Xnew
msheppar
parents: 28856
diff changeset
   150
        //for (int i = 0; i < argv.length; i++) {
a6e3407e9f32 8146299: Disable rmic -Xnew
msheppar
parents: 28856
diff changeset
   151
        //    if (argv[i].equals("-Xnew")) {
a6e3407e9f32 8146299: Disable rmic -Xnew
msheppar
parents: 28856
diff changeset
   152
        //        return (new sun.rmi.rmic.newrmic.Main(out,
a6e3407e9f32 8146299: Disable rmic -Xnew
msheppar
parents: 28856
diff changeset
   153
        //                                              program)).compile(argv);
a6e3407e9f32 8146299: Disable rmic -Xnew
msheppar
parents: 28856
diff changeset
   154
        //    }
a6e3407e9f32 8146299: Disable rmic -Xnew
msheppar
parents: 28856
diff changeset
   155
        //}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (!parseArgs(argv)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (classes.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
22084
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   166
        if ((flags & F_WARNINGS) != 0) {
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   167
            for (Generator g : generators) {
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   168
                if (g instanceof RMIGenerator) {
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   169
                    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
   170
                    break;
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
            }
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   173
        }
fd3c6345eaef 8027536: rmic: add deprecation warning message when generating JRMP static stubs/skeletons
smarks
parents: 21655
diff changeset
   174
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return doCompile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Get the destination directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public File getDestinationDir() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return destDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Parse the arguments for compile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public boolean parseArgs(String argv[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        sourcePathArg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        sysClassPathArg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        classPathString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        destDir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        flags = F_WARNINGS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        tm = System.currentTimeMillis();
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   196
        classes = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        nowrite = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        nocompile = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        keepGenerated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        generatorArgs = getArray("generator.args",true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (generatorArgs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   204
        generators = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        // Pre-process command line for @file arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            argv = CommandLine.parse(argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            error("rmic.cant.read", e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            e.printStackTrace(out instanceof PrintStream ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                              (PrintStream) out :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                              new PrintStream(out, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // Parse arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        for (int i = 0 ; i < argv.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if (argv[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                if (argv[i].equals("-g")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    flags &= ~F_OPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    flags |= F_DEBUG_LINES | F_DEBUG_VARS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                } else if (argv[i].equals("-O")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    flags &= ~F_DEBUG_LINES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    flags &= ~F_DEBUG_VARS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    flags |= F_OPT | F_DEPENDENCIES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                } else if (argv[i].equals("-nowarn")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    flags &= ~F_WARNINGS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                } else if (argv[i].equals("-debug")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    flags |= F_DUMP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                } else if (argv[i].equals("-depend")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    flags |= F_DEPENDENCIES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                } else if (argv[i].equals("-verbose")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    flags |= F_VERBOSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                } else if (argv[i].equals("-nowrite")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    nowrite = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                } else if (argv[i].equals("-Xnocompile")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    nocompile = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    keepGenerated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                } else if (argv[i].equals("-keep") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                           argv[i].equals("-keepgenerated")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    keepGenerated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                } else if (argv[i].equals("-show")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    error("rmic.option.unsupported", "-show");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                } else if (argv[i].equals("-classpath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    if ((i + 1) < argv.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        if (classPathString != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                            error("rmic.option.already.seen", "-classpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        classPathString = argv[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        error("rmic.option.requires.argument", "-classpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                } else if (argv[i].equals("-sourcepath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    if ((i + 1) < argv.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                        if (sourcePathArg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                            error("rmic.option.already.seen", "-sourcepath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                        sourcePathArg = argv[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        error("rmic.option.requires.argument", "-sourcepath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                } else if (argv[i].equals("-bootclasspath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    if ((i + 1) < argv.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                        if (sysClassPathArg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                            error("rmic.option.already.seen", "-bootclasspath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                        sysClassPathArg = argv[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        error("rmic.option.requires.argument", "-bootclasspath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                } else if (argv[i].equals("-d")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    if ((i + 1) < argv.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        if (destDir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                            error("rmic.option.already.seen", "-d");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        destDir = new File(argv[++i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                        argv[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                        if (!destDir.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                            error("rmic.no.such.directory", destDir.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                            usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                        error("rmic.option.requires.argument", "-d");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    if (!checkGeneratorArg(argv,i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                        return false;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        // Now that all generators have had a chance at the args,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // scan what's left for classes and illegal args...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        for (int i = 0; i < argv.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            if (argv[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                if (argv[i].startsWith("-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    error("rmic.no.such.option", argv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    usage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    classes.addElement(argv[i]);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        // If the generators vector is empty, add the default generator...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (generators.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            addGenerator("default");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * If this argument is for a generator, instantiate it, call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * parseArgs(...) and add generator to generators vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Returns false on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    protected boolean checkGeneratorArg(String[] argv, int currentIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        boolean result = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        if (argv[currentIndex].startsWith("-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            String arg = argv[currentIndex].substring(1).toLowerCase(); // Remove '-'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            for (int i = 0; i < generatorArgs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                if (arg.equalsIgnoreCase(generatorArgs[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    // Got a match, add Generator and call parseArgs...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    Generator gen = addGenerator(arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    if (gen == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    result = gen.parseArgs(argv,this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * Instantiate and add a generator to the generators array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    protected Generator addGenerator(String arg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        Generator gen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // Create an instance of the generator and add it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        // the array...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        String className = getString("generator.class." + arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        if (className == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            error("rmic.missing.property",arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            gen = (Generator) Class.forName(className).newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            error("rmic.cannot.instantiate",className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        generators.addElement(gen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        // Get the environment required by this generator...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   409
        Class<?> envClass = BatchEnvironment.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        String env = getString("generator.env." + arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if (env != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                envClass = Class.forName(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                // Is the new class a subclass of the current one?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                if (environmentClass.isAssignableFrom(envClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    // Yes, so switch to the new one...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   421
                    environmentClass = envClass.asSubclass(BatchEnvironment.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    // No. Is the current class a subclass of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    // new one?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    if (!envClass.isAssignableFrom(environmentClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        // No, so it's a conflict...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                        error("rmic.cannot.use.both",environmentClass.getName(),envClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                error("rmic.class.not.found",env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        // If this is the iiop stub generator, cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        // that fact for the jrmp generator...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (arg.equals("iiop")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            iiopGeneration = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return gen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * Grab a resource string and parse it into an array of strings. Assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * comma separated list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @param name The resource name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @param mustExist If true, throws error if resource does not exist. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * false and resource does not exist, returns zero element array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    protected String[] getArray(String name, boolean mustExist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        String[] result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        String value = getString(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if (mustExist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                error("rmic.resource.not.found",name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                return new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        StringTokenizer parser = new StringTokenizer(value,", \t\n\r", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        int count = parser.countTokens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        result = new String[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            result[i] = parser.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Get the correct type of BatchEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public BatchEnvironment getEnv() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        ClassPath classPath =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            BatchEnvironment.createClassPath(classPathString,
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   487
                                             sysClassPathArg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        BatchEnvironment result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        try {
21655
55f32ae4f920 8028229: Fix more raw types lint warning in core libraries
darcy
parents: 18137
diff changeset
   490
            Class<?>[] ctorArgTypes = {OutputStream.class,ClassPath.class,Main.class};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            Object[] ctorArgs = {out,classPath,this};
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   492
            Constructor<? extends BatchEnvironment> constructor =
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   493
                environmentClass.getConstructor(ctorArgTypes);
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   494
            result =  constructor.newInstance(ctorArgs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            result.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            error("rmic.cannot.instantiate",environmentClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * Do the compile with the switches and files already supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public boolean doCompile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        // Create batch environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        BatchEnvironment env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        env.flags |= flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        // Set the classfile version numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        // Compat and 1.1 stubs must retain the old version number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        env.majorVersion = 45;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        env.minorVersion = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        // Preload the "out of memory" error string just in case we run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        // out of memory during the compile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        String noMemoryErrorString = getText("rmic.no.memory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        String stackOverflowErrorString = getText("rmic.stack.overflow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            /** Load the classes on the command line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
             * Replace the entries in classes with the ClassDefinition for the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            for (int i = classes.size()-1; i >= 0; i-- ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                Identifier implClassName =
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   528
                    Identifier.lookup(classes.elementAt(i));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                 * Fix bugid 4049354: support using '.' as an inner class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                 * qualifier on the command line (previously, only mangled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                 * inner class names were understood, like "pkg.Outer$Inner").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                 * The following method, also used by "javap", resolves the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                 * given unmangled inner class name to the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                 * internal identifier.  For example, it translates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                 * "pkg.Outer.Inner" to "pkg.Outer. Inner".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                implClassName = env.resolvePackageQualifiedName(implClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                 * But if we use such an internal inner class name identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                 * to load the class definition, the Java compiler will notice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                 * if the impl class is a "private" inner class and then deny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                 * skeletons (needed unless "-v1.2" is used) the ability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                 * cast to it.  To work around this problem, we mangle inner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                 * class name identifiers to their binary "outer" class name:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                 * "pkg.Outer. Inner" becomes "pkg.Outer$Inner".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                implClassName = Names.mangleClass(implClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                ClassDeclaration decl = env.getClassDeclaration(implClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    ClassDefinition def = decl.getClassDefinition(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    for (int j = 0; j < generators.size(); j++) {
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   556
                        Generator gen = generators.elementAt(j);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        gen.generate(env, def, destDir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                } catch (ClassNotFound ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    env.error(0, "rmic.class.not.found", implClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            // compile all classes that need compilation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            if (!nocompile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                compileAllClasses(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        } catch (OutOfMemoryError ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            // The compiler has run out of memory.  Use the error string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            // which we preloaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            env.output(noMemoryErrorString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        } catch (StackOverflowError ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            env.output(stackOverflowErrorString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        } catch (Error ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            // We allow the compiler to take an exception silently if a program
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            // error has previously been detected.  Presumably, this makes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            // compiler more robust in the face of bad error recovery.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            if (env.nerrors == 0 || env.dump()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                env.error(0, "fatal.error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                ee.printStackTrace(out instanceof PrintStream ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                   (PrintStream) out :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                                   new PrintStream(out, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        } catch (Exception ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            if (env.nerrors == 0 || env.dump()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                env.error(0, "fatal.exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                ee.printStackTrace(out instanceof PrintStream ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                                   (PrintStream) out :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                   new PrintStream(out, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        env.flushErrors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        boolean status = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if (env.nerrors > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            String msg = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            if (env.nerrors > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                msg = getText("rmic.errors", env.nerrors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                msg = getText("rmic.1error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            if (env.nwarnings > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                if (env.nwarnings > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    msg += ", " + getText("rmic.warnings", env.nwarnings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                    msg += ", " + getText("rmic.1warning");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            output(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            status = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            if (env.nwarnings > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                if (env.nwarnings > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    output(getText("rmic.warnings", env.nwarnings));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    output(getText("rmic.1warning"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        // last step is to delete generated source files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        if (!keepGenerated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            env.deleteGeneratedFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        // We're done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        if (env.verbose()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            tm = System.currentTimeMillis() - tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            output(getText("rmic.done_in", Long.toString(tm)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        // Shutdown the environment object and release our resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        // Note that while this is unneccessary when rmic is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        // the command line, there are environments in which rmic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        // from is invoked within a server process, so resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        // reclamation is important...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        env.shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        sourcePathArg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        sysClassPathArg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        classPathString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        destDir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        classes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        generatorArgs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        generators = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        environmentClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        program = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        out = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * Compile all classes that need to be compiled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    public void compileAllClasses (BatchEnvironment env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        throws ClassNotFound,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
               IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
               InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        boolean done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            done = true;
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   670
            for (Enumeration<?> e = env.getClasses() ; e.hasMoreElements() ; ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                ClassDeclaration c = (ClassDeclaration)e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                done = compileClass(c,buf,env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        } while (!done);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Compile a single class.
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   679
     * Fallthrough is intentional
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     */
28856
1c525c8d1cf7 8069255: Suppress deprecation warnings in jdk.rmic module (jdk repo)
amlu
parents: 27565
diff changeset
   681
    @SuppressWarnings({"fallthrough", "deprecation"})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    public boolean compileClass (ClassDeclaration c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                                 ByteArrayOutputStream buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                                 BatchEnvironment env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        throws ClassNotFound,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
               IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
               InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        boolean done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        env.flushErrors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        SourceClass src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        switch (c.getStatus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        case CS_UNDEFINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                if (!env.dependencies()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                // fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        case CS_SOURCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                env.loadDefinition(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                if (c.getStatus() != CS_PARSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                // fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        case CS_PARSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                if (c.getClassDefinition().isInsideLocal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                // If we get to here, then compilation is going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                // to occur. If the -Xnocompile switch is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                // then fail. Note that this check is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                // here because this method is called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                // generators, not just from within this class...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                if (nocompile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                    throw new IOException("Compilation required, but -Xnocompile option in effect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                src = (SourceClass)c.getClassDefinition(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                src.check(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                c.setDefinition(src, CS_CHECKED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                // fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        case CS_CHECKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                src = (SourceClass)c.getClassDefinition(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                // bail out if there were any errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                if (src.getError()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                    c.setDefinition(src, CS_COMPILED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                buf.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                src.compile(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                c.setDefinition(src, CS_COMPILED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                src.cleanup(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                if (src.getError() || nowrite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                String pkgName = c.getName().getQualifier().toString().replace('.', File.separatorChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                String className = c.getName().getFlatName().toString().replace('.', SIGC_INNERCLASS) + ".class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                File file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                if (destDir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                    if (pkgName.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                        file = new File(destDir, pkgName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                        if (!file.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                            file.mkdirs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                        file = new File(file, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                        file = new File(destDir, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    ClassFile classfile = (ClassFile)src.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    if (classfile.isZipped()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                        env.error(0, "cant.write", classfile.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    file = new File(classfile.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                    file = new File(file.getParent(), className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                // Create the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    FileOutputStream out = new FileOutputStream(file.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                    buf.writeTo(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                    out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                    if (env.verbose()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                        output(getText("rmic.wrote", file.getPath()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                } catch (IOException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                    env.error(0, "cant.write", file.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        return done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * Main program
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    public static void main(String argv[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        Main compiler = new Main(System.out, "rmic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        System.exit(compiler.compile(argv) ? 0 : 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * Return the string value of a named resource in the rmic.properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * resource bundle.  If the resource is not found, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    public static String getString(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        if (!resourcesInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            initResources();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        // To enable extensions, search the 'resourcesExt'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        // bundle first, followed by the 'resources' bundle...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        if (resourcesExt != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                return resourcesExt.getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            } catch (MissingResourceException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            return resources.getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        } catch (MissingResourceException ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    private static boolean resourcesInitialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    private static ResourceBundle resources;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    private static ResourceBundle resourcesExt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    private static void initResources() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            resources =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                ResourceBundle.getBundle("sun.rmi.rmic.resources.rmic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            resourcesInitialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                resourcesExt =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    ResourceBundle.getBundle("sun.rmi.rmic.resources.rmicext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            } catch (MissingResourceException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        } catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            throw new Error("fatal: missing resource bundle: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                            e.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    public static String getText(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        String message = getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        if (message == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            message = "no text found: \"" + key + "\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        return message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    public static String getText(String key, int num) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        return getText(key, Integer.toString(num), null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    public static String getText(String key, String arg0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        return getText(key, arg0, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    public static String getText(String key, String arg0, String arg1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        return getText(key, arg0, arg1, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    public static String getText(String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                                 String arg0, String arg1, String arg2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        String format = getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        if (format == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            format = "no text found: key = \"" + key + "\", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                "arguments = \"{0}\", \"{1}\", \"{2}\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        String[] args = new String[3];
18137
264000e285e9 8015470: Remove redundant calls of toString() on String objects
dholmes
parents: 14342
diff changeset
   874
        args[0] = (arg0 != null ? arg0 : "null");
264000e285e9 8015470: Remove redundant calls of toString() on String objects
dholmes
parents: 14342
diff changeset
   875
        args[1] = (arg1 != null ? arg1 : "null");
264000e285e9 8015470: Remove redundant calls of toString() on String objects
dholmes
parents: 14342
diff changeset
   876
        args[2] = (arg2 != null ? arg2 : "null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
12197
565357741463 7152007: Fix warnings in sun/rmi/rmic
khazra
parents: 12045
diff changeset
   878
        return java.text.MessageFormat.format(format, (Object[]) args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
}