author | alundblad |
Mon, 21 Sep 2015 11:19:10 +0200 | |
changeset 32799 | ee577901f4bb |
parent 32542 | f4e4f4c4f9f4 |
child 33553 | 9a742b6b95d3 |
permissions | -rw-r--r-- |
25605
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
1 |
/* |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
27388
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
25605
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
4 |
* |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
10 |
* |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
15 |
* accompanied this code). |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
16 |
* |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
20 |
* |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
23 |
* questions. |
c2d72342fe19
8050408: A few new Java src files for sjavac are missing copyright notices
jjg
parents:
25299
diff
changeset
|
24 |
*/ |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
25 |
package com.sun.tools.sjavac.comp; |
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
26 |
|
27388
d694da45bd7a
8062676: Tests which leak lots of file managers should be fixed (group 2)
jjg
parents:
26992
diff
changeset
|
27 |
import java.io.IOException; |
32542
f4e4f4c4f9f4
8129114: Sjavac should stream back compiler output to the client as soon as it becomes available
alundblad
parents:
32335
diff
changeset
|
28 |
import java.io.PrintWriter; |
f4e4f4c4f9f4
8129114: Sjavac should stream back compiler output to the client as soon as it becomes available
alundblad
parents:
32335
diff
changeset
|
29 |
import java.io.Writer; |
32335 | 30 |
import java.nio.file.Files; |
31 |
import java.nio.file.Path; |
|
32 |
import java.util.ArrayList; |
|
33 |
import java.util.Collections; |
|
34 |
import java.util.HashMap; |
|
35 |
import java.util.HashSet; |
|
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
36 |
import java.util.List; |
32335 | 37 |
import java.util.Map; |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
38 |
import java.util.Set; |
32799 | 39 |
import java.util.stream.Stream; |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
40 |
|
32799 | 41 |
import com.sun.tools.javac.file.JavacFileManager; |
42 |
import com.sun.tools.javac.main.Main; |
|
43 |
import com.sun.tools.javac.util.Context; |
|
32335 | 44 |
import com.sun.tools.sjavac.JavacState; |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
27388
diff
changeset
|
45 |
import com.sun.tools.sjavac.Log; |
32335 | 46 |
import com.sun.tools.sjavac.Module; |
47 |
import com.sun.tools.sjavac.ProblemException; |
|
48 |
import com.sun.tools.sjavac.Source; |
|
49 |
import com.sun.tools.sjavac.Transformer; |
|
26991
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
50 |
import com.sun.tools.sjavac.Util; |
32799 | 51 |
import com.sun.tools.sjavac.options.Option; |
32335 | 52 |
import com.sun.tools.sjavac.options.Options; |
53 |
import com.sun.tools.sjavac.options.SourceLocation; |
|
26098
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
54 |
import com.sun.tools.sjavac.server.Sjavac; |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
55 |
|
32799 | 56 |
import javax.tools.JavaFileManager; |
57 |
||
26098
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
58 |
/** |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
59 |
* The sjavac implementation that interacts with javac and performs the actual |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
60 |
* compilation. |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
61 |
* |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
62 |
* <p><b>This is NOT part of any supported API. |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
63 |
* If you write code that depends on this, you do so at your own risk. |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
64 |
* This code and its internal interfaces are subject to change or |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
65 |
* deletion without notice.</b> |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
66 |
*/ |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
67 |
public class SjavacImpl implements Sjavac { |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
68 |
|
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
69 |
@Override |
32542
f4e4f4c4f9f4
8129114: Sjavac should stream back compiler output to the client as soon as it becomes available
alundblad
parents:
32335
diff
changeset
|
70 |
public int compile(String[] args, Writer out, Writer err) { |
32335 | 71 |
Options options; |
72 |
try { |
|
73 |
options = Options.parseArgs(args); |
|
74 |
} catch (IllegalArgumentException e) { |
|
75 |
Log.error(e.getMessage()); |
|
32542
f4e4f4c4f9f4
8129114: Sjavac should stream back compiler output to the client as soon as it becomes available
alundblad
parents:
32335
diff
changeset
|
76 |
return RC_FATAL; |
32335 | 77 |
} |
78 |
||
79 |
Log.setLogLevel(options.getLogLevel()); |
|
80 |
||
81 |
if (!validateOptions(options)) |
|
32542
f4e4f4c4f9f4
8129114: Sjavac should stream back compiler output to the client as soon as it becomes available
alundblad
parents:
32335
diff
changeset
|
82 |
return RC_FATAL; |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
83 |
|
32335 | 84 |
if (!createIfMissing(options.getDestDir())) |
32542
f4e4f4c4f9f4
8129114: Sjavac should stream back compiler output to the client as soon as it becomes available
alundblad
parents:
32335
diff
changeset
|
85 |
return RC_FATAL; |
32335 | 86 |
|
32799 | 87 |
Path stateDir = options.getStateDir(); |
88 |
if (stateDir != null && !createIfMissing(options.getStateDir())) |
|
32542
f4e4f4c4f9f4
8129114: Sjavac should stream back compiler output to the client as soon as it becomes available
alundblad
parents:
32335
diff
changeset
|
89 |
return RC_FATAL; |
32335 | 90 |
|
91 |
Path gensrc = options.getGenSrcDir(); |
|
92 |
if (gensrc != null && !createIfMissing(gensrc)) |
|
32542
f4e4f4c4f9f4
8129114: Sjavac should stream back compiler output to the client as soon as it becomes available
alundblad
parents:
32335
diff
changeset
|
93 |
return RC_FATAL; |
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
27388
diff
changeset
|
94 |
|
32335 | 95 |
Path hdrdir = options.getHeaderDir(); |
96 |
if (hdrdir != null && !createIfMissing(hdrdir)) |
|
32542
f4e4f4c4f9f4
8129114: Sjavac should stream back compiler output to the client as soon as it becomes available
alundblad
parents:
32335
diff
changeset
|
97 |
return RC_FATAL; |
32335 | 98 |
|
32799 | 99 |
if (stateDir == null) { |
100 |
// Prepare context. Direct logging to our byte array stream. |
|
101 |
Context context = new Context(); |
|
102 |
PrintWriter writer = new PrintWriter(err); |
|
103 |
com.sun.tools.javac.util.Log.preRegister(context, writer); |
|
104 |
JavacFileManager.preRegister(context); |
|
32335 | 105 |
|
32799 | 106 |
// Prepare arguments |
107 |
String[] passThroughArgs = Stream.of(args) |
|
108 |
.filter(arg -> !arg.startsWith(Option.SERVER.arg)) |
|
109 |
.toArray(String[]::new); |
|
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
110 |
|
32799 | 111 |
// Compile |
112 |
com.sun.tools.javac.main.Main compiler = new com.sun.tools.javac.main.Main("javac", writer); |
|
113 |
Main.Result result = compiler.compile(passThroughArgs, context); |
|
32335 | 114 |
|
32799 | 115 |
// Clean up |
116 |
JavaFileManager fileManager = context.get(JavaFileManager.class); |
|
117 |
if (fileManager instanceof JavacFileManager) { |
|
118 |
((JavacFileManager) fileManager).close(); |
|
119 |
} |
|
120 |
return result.exitCode; |
|
121 |
||
122 |
} else { |
|
123 |
// Load the prev build state database. |
|
124 |
JavacState javac_state = JavacState.load(options, out, err); |
|
125 |
||
126 |
// Setup the suffix rules from the command line. |
|
127 |
Map<String, Transformer> suffixRules = new HashMap<>(); |
|
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
27388
diff
changeset
|
128 |
|
32799 | 129 |
// Handling of .java-compilation |
130 |
suffixRules.putAll(javac_state.getJavaSuffixRule()); |
|
131 |
||
132 |
// Handling of -copy and -tr |
|
133 |
suffixRules.putAll(options.getTranslationRules()); |
|
32335 | 134 |
|
32799 | 135 |
// All found modules are put here. |
136 |
Map<String,Module> modules = new HashMap<>(); |
|
137 |
// We start out in the legacy empty no-name module. |
|
138 |
// As soon as we stumble on a module-info.java file we change to that module. |
|
139 |
Module current_module = new Module("", ""); |
|
140 |
modules.put("", current_module); |
|
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
141 |
|
32799 | 142 |
// Find all sources, use the suffix rules to know which files are sources. |
143 |
Map<String,Source> sources = new HashMap<>(); |
|
26991
88d998b3bb4b
8056258: Analysis of public API does not take super classes into account
alundblad
parents:
26107
diff
changeset
|
144 |
|
32799 | 145 |
// Find the files, this will automatically populate the found modules |
146 |
// with found packages where the sources are found! |
|
147 |
findSourceFiles(options.getSources(), |
|
148 |
suffixRules.keySet(), |
|
149 |
sources, |
|
150 |
modules, |
|
151 |
current_module, |
|
152 |
options.isDefaultPackagePermitted(), |
|
153 |
false); |
|
154 |
||
155 |
if (sources.isEmpty()) { |
|
156 |
Log.error("Found nothing to compile!"); |
|
157 |
return RC_FATAL; |
|
158 |
} |
|
32335 | 159 |
|
160 |
||
32799 | 161 |
// Create a map of all source files that are available for linking. Both -src and |
162 |
// -sourcepath point to such files. It is possible to specify multiple |
|
163 |
// -sourcepath options to enable different filtering rules. If the |
|
164 |
// filters are the same for multiple sourcepaths, they may be concatenated |
|
165 |
// using :(;). Before sending the list of sourcepaths to javac, they are |
|
166 |
// all concatenated. The list created here is used by the SmartFileWrapper to |
|
167 |
// make sure only the correct sources are actually available. |
|
168 |
// We might find more modules here as well. |
|
169 |
Map<String,Source> sources_to_link_to = new HashMap<>(); |
|
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
27388
diff
changeset
|
170 |
|
32799 | 171 |
List<SourceLocation> sourceResolutionLocations = new ArrayList<>(); |
172 |
sourceResolutionLocations.addAll(options.getSources()); |
|
173 |
sourceResolutionLocations.addAll(options.getSourceSearchPaths()); |
|
174 |
findSourceFiles(sourceResolutionLocations, |
|
175 |
Collections.singleton(".java"), |
|
176 |
sources_to_link_to, |
|
177 |
modules, |
|
178 |
current_module, |
|
179 |
options.isDefaultPackagePermitted(), |
|
180 |
true); |
|
32335 | 181 |
|
32799 | 182 |
// Add the set of sources to the build database. |
183 |
javac_state.now().flattenPackagesSourcesAndArtifacts(modules); |
|
184 |
javac_state.now().checkInternalState("checking sources", false, sources); |
|
185 |
javac_state.now().checkInternalState("checking linked sources", true, sources_to_link_to); |
|
186 |
javac_state.setVisibleSources(sources_to_link_to); |
|
32335 | 187 |
|
32799 | 188 |
int round = 0; |
189 |
printRound(round); |
|
32335 | 190 |
|
32799 | 191 |
// If there is any change in the source files, taint packages |
192 |
// and mark the database in need of saving. |
|
193 |
javac_state.checkSourceStatus(false); |
|
32335 | 194 |
|
32799 | 195 |
// Find all existing artifacts. Their timestamp will match the last modified timestamps stored |
196 |
// in javac_state, simply because loading of the JavacState will clean out all artifacts |
|
197 |
// that do not match the javac_state database. |
|
198 |
javac_state.findAllArtifacts(); |
|
32335 | 199 |
|
32799 | 200 |
// Remove unidentified artifacts from the bin, gensrc and header dirs. |
201 |
// (Unless we allow them to be there.) |
|
202 |
// I.e. artifacts that are not known according to the build database (javac_state). |
|
203 |
// For examples, files that have been manually copied into these dirs. |
|
204 |
// Artifacts with bad timestamps (ie the on disk timestamp does not match the timestamp |
|
205 |
// in javac_state) have already been removed when the javac_state was loaded. |
|
206 |
if (!options.areUnidentifiedArtifactsPermitted()) { |
|
207 |
javac_state.removeUnidentifiedArtifacts(); |
|
208 |
} |
|
209 |
// Go through all sources and taint all packages that miss artifacts. |
|
210 |
javac_state.taintPackagesThatMissArtifacts(); |
|
32335 | 211 |
|
32799 | 212 |
// Check recorded classpath public apis. Taint packages that depend on |
213 |
// classpath classes whose public apis have changed. |
|
214 |
javac_state.taintPackagesDependingOnChangedClasspathPackages(); |
|
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
215 |
|
32799 | 216 |
// Now clean out all known artifacts belonging to tainted packages. |
217 |
javac_state.deleteClassArtifactsInTaintedPackages(); |
|
218 |
// Copy files, for example property files, images files, xml files etc etc. |
|
219 |
javac_state.performCopying(Util.pathToFile(options.getDestDir()), suffixRules); |
|
220 |
// Translate files, for example compile properties or compile idls. |
|
221 |
javac_state.performTranslation(Util.pathToFile(gensrc), suffixRules); |
|
222 |
// Add any potentially generated java sources to the tobe compiled list. |
|
223 |
// (Generated sources must always have a package.) |
|
224 |
Map<String,Source> generated_sources = new HashMap<>(); |
|
32335 | 225 |
|
32799 | 226 |
try { |
32335 | 227 |
|
32799 | 228 |
Source.scanRoot(Util.pathToFile(options.getGenSrcDir()), Util.set(".java"), null, null, null, null, |
229 |
generated_sources, modules, current_module, false, true, false); |
|
230 |
javac_state.now().flattenPackagesSourcesAndArtifacts(modules); |
|
231 |
// Recheck the the source files and their timestamps again. |
|
232 |
javac_state.checkSourceStatus(true); |
|
32335 | 233 |
|
32799 | 234 |
// Now do a safety check that the list of source files is identical |
235 |
// to the list Make believes we are compiling. If we do not get this |
|
236 |
// right, then incremental builds will fail with subtility. |
|
237 |
// If any difference is detected, then we will fail hard here. |
|
238 |
// This is an important safety net. |
|
239 |
javac_state.compareWithMakefileList(Util.pathToFile(options.getSourceReferenceList())); |
|
32335 | 240 |
|
32799 | 241 |
// Do the compilations, repeatedly until no tainted packages exist. |
242 |
boolean again; |
|
243 |
// Collect the name of all compiled packages. |
|
244 |
Set<String> recently_compiled = new HashSet<>(); |
|
245 |
boolean[] rc = new boolean[1]; |
|
32335 | 246 |
|
32799 | 247 |
CompilationService compilationService = new CompilationService(); |
248 |
do { |
|
249 |
if (round > 0) |
|
250 |
printRound(round); |
|
251 |
// Clean out artifacts in tainted packages. |
|
252 |
javac_state.deleteClassArtifactsInTaintedPackages(); |
|
253 |
again = javac_state.performJavaCompilations(compilationService, options, recently_compiled, rc); |
|
254 |
if (!rc[0]) { |
|
255 |
Log.debug("Compilation failed."); |
|
256 |
break; |
|
257 |
} |
|
258 |
if (!again) { |
|
259 |
Log.debug("Nothing left to do."); |
|
260 |
} |
|
261 |
round++; |
|
262 |
} while (again); |
|
263 |
Log.debug("No need to do another round."); |
|
264 |
||
265 |
// Only update the state if the compile went well. |
|
266 |
if (rc[0]) { |
|
267 |
javac_state.save(); |
|
268 |
// Reflatten only the artifacts. |
|
269 |
javac_state.now().flattenArtifacts(modules); |
|
270 |
// Remove artifacts that were generated during the last compile, but not this one. |
|
271 |
javac_state.removeSuperfluousArtifacts(recently_compiled); |
|
32335 | 272 |
} |
273 |
||
32799 | 274 |
return rc[0] ? RC_OK : RC_FATAL; |
275 |
} catch (ProblemException e) { |
|
276 |
Log.error(e.getMessage()); |
|
277 |
return RC_FATAL; |
|
278 |
} catch (Exception e) { |
|
279 |
e.printStackTrace(new PrintWriter(err)); |
|
280 |
return RC_FATAL; |
|
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
281 |
} |
26992
92e69fa21956
8059349: Public API scanning should be implemented in the form of a TaskListener
alundblad
parents:
26991
diff
changeset
|
282 |
} |
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
283 |
} |
26088 | 284 |
|
285 |
@Override |
|
26098
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
286 |
public void shutdown() { |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
287 |
// Nothing to clean up |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
288 |
} |
32588700060b
8048457: Sjavac should not use portfiles, sockets, etc if background=false
alundblad
parents:
26088
diff
changeset
|
289 |
|
32335 | 290 |
private static boolean validateOptions(Options options) { |
291 |
||
292 |
String err = null; |
|
293 |
||
294 |
if (options.getDestDir() == null) { |
|
295 |
err = "Please specify output directory."; |
|
296 |
} else if (options.isJavaFilesAmongJavacArgs()) { |
|
297 |
err = "Sjavac does not handle explicit compilation of single .java files."; |
|
298 |
} else if (options.getServerConf() == null) { |
|
299 |
err = "No server configuration provided."; |
|
300 |
} else if (!options.getImplicitPolicy().equals("none")) { |
|
301 |
err = "The only allowed setting for sjavac is -implicit:none"; |
|
32799 | 302 |
} else if (options.getSources().isEmpty() && options.getStateDir() != null) { |
303 |
err = "You have to specify -src when using --state-dir."; |
|
32335 | 304 |
} else if (options.getTranslationRules().size() > 1 |
305 |
&& options.getGenSrcDir() == null) { |
|
306 |
err = "You have translators but no gensrc dir (-s) specified!"; |
|
307 |
} |
|
308 |
||
309 |
if (err != null) |
|
310 |
Log.error(err); |
|
311 |
||
312 |
return err == null; |
|
313 |
||
26088 | 314 |
} |
315 |
||
32335 | 316 |
private static boolean createIfMissing(Path dir) { |
317 |
||
318 |
if (Files.isDirectory(dir)) |
|
319 |
return true; |
|
320 |
||
321 |
if (Files.exists(dir)) { |
|
322 |
Log.error(dir + " is not a directory."); |
|
323 |
return false; |
|
324 |
} |
|
325 |
||
326 |
try { |
|
327 |
Files.createDirectories(dir); |
|
328 |
} catch (IOException e) { |
|
329 |
Log.error("Could not create directory: " + e.getMessage()); |
|
330 |
return false; |
|
331 |
} |
|
332 |
||
333 |
return true; |
|
334 |
} |
|
335 |
||
336 |
/** Find source files in the given source locations. */ |
|
337 |
public static void findSourceFiles(List<SourceLocation> sourceLocations, |
|
338 |
Set<String> sourceTypes, |
|
339 |
Map<String,Source> foundFiles, |
|
340 |
Map<String, Module> foundModules, |
|
341 |
Module currentModule, |
|
342 |
boolean permitSourcesInDefaultPackage, |
|
343 |
boolean inLinksrc) { |
|
344 |
||
345 |
for (SourceLocation source : sourceLocations) { |
|
346 |
source.findSourceFiles(sourceTypes, |
|
347 |
foundFiles, |
|
348 |
foundModules, |
|
349 |
currentModule, |
|
350 |
permitSourcesInDefaultPackage, |
|
351 |
inLinksrc); |
|
31115
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
27388
diff
changeset
|
352 |
} |
8d8e98052d5d
8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents:
27388
diff
changeset
|
353 |
} |
32335 | 354 |
|
355 |
private static void printRound(int round) { |
|
356 |
Log.debug("****************************************"); |
|
357 |
Log.debug("* Round " + round + " *"); |
|
358 |
Log.debug("****************************************"); |
|
359 |
} |
|
25299
b4a7dcd657f5
8048594: The sjavac client/server protocol should be hidden behind an interface
alundblad
parents:
diff
changeset
|
360 |
} |