2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.rmi.rmic.newrmic;
|
|
27 |
|
|
28 |
import com.sun.javadoc.ClassDoc;
|
|
29 |
import com.sun.javadoc.RootDoc;
|
|
30 |
import java.io.File;
|
|
31 |
import java.text.MessageFormat;
|
|
32 |
import java.util.ArrayList;
|
|
33 |
import java.util.Collections;
|
|
34 |
import java.util.List;
|
|
35 |
|
|
36 |
import static sun.rmi.rmic.newrmic.Constants.*;
|
|
37 |
|
|
38 |
/**
|
|
39 |
* The environment for an rmic compilation batch.
|
|
40 |
*
|
|
41 |
* A BatchEnvironment contains a RootDoc, which is the entry point
|
|
42 |
* into the doclet environment for the associated rmic compilation
|
|
43 |
* batch. A BatchEnvironment collects the source files generated
|
|
44 |
* during the batch's execution, for eventual source code compilation
|
|
45 |
* and, possibly, deletion. Errors that occur during generation
|
|
46 |
* activity should be reported through the BatchEnvironment's "error"
|
|
47 |
* method.
|
|
48 |
*
|
|
49 |
* A protocol-specific generator class may require the use of a
|
|
50 |
* particular BatchEnvironment subclass for enhanced environment
|
|
51 |
* functionality. A BatchEnvironment subclass must declare a
|
|
52 |
* public constructor with one parameter of type RootDoc.
|
|
53 |
*
|
|
54 |
* WARNING: The contents of this source file are not part of any
|
|
55 |
* supported API. Code that depends on them does so at its own risk:
|
|
56 |
* they are subject to change or removal without notice.
|
|
57 |
*
|
|
58 |
* @author Peter Jones
|
|
59 |
**/
|
|
60 |
public class BatchEnvironment {
|
|
61 |
|
|
62 |
private final RootDoc rootDoc;
|
|
63 |
|
|
64 |
/** cached ClassDoc for certain types used by rmic */
|
|
65 |
private final ClassDoc docRemote;
|
|
66 |
private final ClassDoc docException;
|
|
67 |
private final ClassDoc docRemoteException;
|
|
68 |
private final ClassDoc docRuntimeException;
|
|
69 |
|
|
70 |
private boolean verbose = false;
|
|
71 |
private final List<File> generatedFiles = new ArrayList<File>();
|
|
72 |
|
|
73 |
/**
|
|
74 |
* Creates a new BatchEnvironment with the specified RootDoc.
|
|
75 |
**/
|
|
76 |
public BatchEnvironment(RootDoc rootDoc) {
|
|
77 |
this.rootDoc = rootDoc;
|
|
78 |
|
|
79 |
/*
|
|
80 |
* Initialize cached ClassDoc for types used by rmic. Note
|
|
81 |
* that any of these could be null if the boot class path is
|
|
82 |
* incorrect, which could cause a NullPointerException later.
|
|
83 |
*/
|
|
84 |
docRemote = rootDoc().classNamed(REMOTE);
|
|
85 |
docException = rootDoc().classNamed(EXCEPTION);
|
|
86 |
docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
|
|
87 |
docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
|
|
88 |
}
|
|
89 |
|
|
90 |
/**
|
|
91 |
* Returns the RootDoc for this environment.
|
|
92 |
**/
|
|
93 |
public RootDoc rootDoc() {
|
|
94 |
return rootDoc;
|
|
95 |
}
|
|
96 |
|
|
97 |
public ClassDoc docRemote() { return docRemote; }
|
|
98 |
public ClassDoc docException() { return docException; }
|
|
99 |
public ClassDoc docRemoteException() { return docRemoteException; }
|
|
100 |
public ClassDoc docRuntimeException() { return docRuntimeException; }
|
|
101 |
|
|
102 |
/**
|
|
103 |
* Sets this environment's verbosity status.
|
|
104 |
**/
|
|
105 |
public void setVerbose(boolean verbose) {
|
|
106 |
this.verbose = verbose;
|
|
107 |
}
|
|
108 |
|
|
109 |
/**
|
|
110 |
* Returns this environment's verbosity status.
|
|
111 |
**/
|
|
112 |
public boolean verbose() {
|
|
113 |
return verbose;
|
|
114 |
}
|
|
115 |
|
|
116 |
/**
|
|
117 |
* Adds the specified file to the list of source files generated
|
|
118 |
* during this batch.
|
|
119 |
**/
|
|
120 |
public void addGeneratedFile(File file) {
|
|
121 |
generatedFiles.add(file);
|
|
122 |
}
|
|
123 |
|
|
124 |
/**
|
|
125 |
* Returns the list of files generated during this batch.
|
|
126 |
**/
|
|
127 |
public List<File> generatedFiles() {
|
|
128 |
return Collections.unmodifiableList(generatedFiles);
|
|
129 |
}
|
|
130 |
|
|
131 |
/**
|
|
132 |
* Outputs the specified (non-error) message.
|
|
133 |
**/
|
|
134 |
public void output(String msg) {
|
|
135 |
rootDoc.printNotice(msg);
|
|
136 |
}
|
|
137 |
|
|
138 |
/**
|
|
139 |
* Reports an error using the specified resource key and text
|
|
140 |
* formatting arguments.
|
|
141 |
**/
|
|
142 |
public void error(String key, String... args) {
|
|
143 |
rootDoc.printError(Resources.getText(key, args));
|
|
144 |
}
|
|
145 |
}
|