Skip to content

Commit 803f1ad

Browse files
committed
JavacCompiler: remove superfluous blank lines
Without sacrificing readability or logical coherence, I think we can be a bit more economical when using blank lines. Less scrolling in the editor, but still enough optical separatory. It is always arguable how much is noo little or too much. I hope, I found a good balance.
1 parent 0b016e4 commit 803f1ad

File tree

1 file changed

+1
-39
lines changed
  • plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac

1 file changed

+1
-39
lines changed

plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,9 @@ protected static class Messages {
187187
}
188188

189189
private static final Object LOCK = new Object();
190-
191190
private static final String JAVAC_CLASSNAME = "com.sun.tools.javac.Main";
192191

193192
private volatile Class<?> javacClass;
194-
195193
private final Deque<Class<?>> javacClasses = new ConcurrentLinkedDeque<>();
196194

197195
@Inject
@@ -217,26 +215,22 @@ public String getCompilerId() {
217215
@Override
218216
public CompilerResult performCompile(CompilerConfiguration config) throws CompilerException {
219217
File destinationDir = new File(config.getOutputLocation());
220-
221218
if (!destinationDir.exists()) {
222219
destinationDir.mkdirs();
223220
}
224221

225222
String[] sourceFiles = getSourceFiles(config);
226-
227223
if ((sourceFiles == null) || (sourceFiles.length == 0)) {
228224
return new CompilerResult();
229225
}
230226

231227
logCompiling(sourceFiles, config);
232228

233229
String[] args = buildCompilerArguments(config, sourceFiles);
234-
235230
CompilerResult result;
236231

237232
if (config.isFork()) {
238233
String executable = config.getExecutable();
239-
240234
if (StringUtils.isEmpty(executable)) {
241235
try {
242236
executable = getJavacExecutable();
@@ -247,7 +241,6 @@ public CompilerResult performCompile(CompilerConfiguration config) throws Compil
247241
executable = "javac";
248242
}
249243
}
250-
251244
result = compileOutOfProcess(config, executable, args);
252245
} else {
253246
if (isJava16() && !config.isForceJavacCompilerUse()) {
@@ -286,9 +279,7 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
286279
// ----------------------------------------------------------------------
287280

288281
File destinationDir = new File(config.getOutputLocation());
289-
290282
args.add("-d");
291-
292283
args.add(destinationDir.getAbsolutePath());
293284

294285
// ----------------------------------------------------------------------
@@ -298,14 +289,12 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
298289
List<String> classpathEntries = config.getClasspathEntries();
299290
if (classpathEntries != null && !classpathEntries.isEmpty()) {
300291
args.add("-classpath");
301-
302292
args.add(getPathString(classpathEntries));
303293
}
304294

305295
List<String> modulepathEntries = config.getModulepathEntries();
306296
if (modulepathEntries != null && !modulepathEntries.isEmpty()) {
307297
args.add("--module-path");
308-
309298
args.add(getPathString(modulepathEntries));
310299
}
311300

@@ -314,7 +303,6 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
314303
// always pass source path, even if sourceFiles are declared,
315304
// needed for jsr269 annotation processing, see MCOMPILER-98
316305
args.add("-sourcepath");
317-
318306
args.add(getPathString(sourceLocations));
319307
}
320308
if (!isJava16() || config.isForceJavacCompilerUse() || config.isFork()) {
@@ -326,7 +314,6 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
326314

327315
if (config.getGeneratedSourcesDirectory() != null) {
328316
config.getGeneratedSourcesDirectory().mkdirs();
329-
330317
args.add("-s");
331318
args.add(config.getGeneratedSourcesDirectory().getAbsolutePath());
332319
}
@@ -341,7 +328,6 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
341328
if (i > 0) {
342329
buffer.append(",");
343330
}
344-
345331
buffer.append(procs[i]);
346332
}
347333
args.add(buffer.toString());
@@ -452,13 +438,10 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
452438
}
453439

454440
args.add(key);
455-
456441
String value = entry.getValue();
457-
458442
if (StringUtils.isEmpty(value)) {
459443
continue;
460444
}
461-
462445
args.add(value);
463446
}
464447

@@ -499,11 +482,9 @@ private static boolean isPreJava16(CompilerConfiguration config) {
499482
if (v == null) {
500483
v = config.getCompilerVersion();
501484
}
502-
503485
if (v == null) {
504486
v = config.getSourceVersion();
505487
}
506-
507488
if (v == null) {
508489
return true;
509490
}
@@ -523,11 +504,9 @@ private static boolean isPreJava18(CompilerConfiguration config) {
523504
if (v == null) {
524505
v = config.getCompilerVersion();
525506
}
526-
527507
if (v == null) {
528508
v = config.getSourceVersion();
529509
}
530-
531510
if (v == null) {
532511
return true;
533512
}
@@ -545,17 +524,14 @@ private static boolean isPreJava18(CompilerConfiguration config) {
545524
}
546525

547526
private static boolean isPreJava9(CompilerConfiguration config) {
548-
549527
String v = config.getReleaseVersion();
550528

551529
if (v == null) {
552530
v = config.getCompilerVersion();
553531
}
554-
555532
if (v == null) {
556533
v = config.getSourceVersion();
557534
}
558-
559535
if (v == null) {
560536
return true;
561537
}
@@ -596,7 +572,6 @@ protected CompilerResult compileOutOfProcess(CompilerConfiguration config, Strin
596572
Commandline cli = new Commandline();
597573

598574
cli.setWorkingDirectory(config.getWorkingDirectory().getAbsolutePath());
599-
600575
cli.setExecutable(executable);
601576

602577
try {
@@ -608,7 +583,6 @@ protected CompilerResult compileOutOfProcess(CompilerConfiguration config, Strin
608583
if (!StringUtils.isEmpty(config.getMaxmem())) {
609584
cli.addArguments(new String[] {"-J-Xmx" + config.getMaxmem()});
610585
}
611-
612586
if (!StringUtils.isEmpty(config.getMeminitial())) {
613587
cli.addArguments(new String[] {"-J-Xms" + config.getMeminitial()});
614588
}
@@ -623,9 +597,7 @@ protected CompilerResult compileOutOfProcess(CompilerConfiguration config, Strin
623597
}
624598

625599
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
626-
627600
int returnCode;
628-
629601
List<CompilerMessage> messages;
630602

631603
if (getLog().isDebugEnabled()) {
@@ -700,16 +672,12 @@ protected CompilerResult compileInProcessWithProperClassloader(Class<?> javacCla
700672
*/
701673
private static CompilerResult compileInProcess0(Class<?> javacClass, String[] args) throws CompilerException {
702674
StringWriter out = new StringWriter();
703-
704675
Integer ok;
705-
706676
List<CompilerMessage> messages;
707677

708678
try {
709679
Method compile = javacClass.getMethod("compile", new Class[] {String[].class, PrintWriter.class});
710-
711680
ok = (Integer) compile.invoke(null, new Object[] {args, new PrintWriter(out)});
712-
713681
messages = parseModernStream(ok, new BufferedReader(new StringReader(out.toString())));
714682
} catch (NoSuchMethodException | IOException | InvocationTargetException | IllegalAccessException e) {
715683
throw new CompilerException("Error while executing the compiler.", e);
@@ -926,7 +894,6 @@ static String getTextStartingWithPrefix(String text, String[] prefixes) {
926894
*/
927895
static CompilerMessage parseModernError(int exitCode, String error) {
928896
final StringTokenizer tokens = new StringTokenizer(error, ":");
929-
930897
CompilerMessage.Kind messageKind = exitCode == 0 ? WARNING : ERROR;
931898

932899
try {
@@ -1039,15 +1006,11 @@ private File createFileWithArguments(String[] args, String outputDirectory) thro
10391006
}
10401007

10411008
writer = new PrintWriter(new FileWriter(tempFile));
1042-
10431009
for (String arg : args) {
10441010
String argValue = arg.replace(File.separatorChar, '/');
1045-
10461011
writer.write("\"" + argValue + "\"");
1047-
10481012
writer.println();
10491013
}
1050-
10511014
writer.flush();
10521015

10531016
return tempFile;
@@ -1068,9 +1031,9 @@ private File createFileWithArguments(String[] args, String outputDirectory) thro
10681031
*/
10691032
private static String getJavacExecutable() throws IOException {
10701033
String javacCommand = "javac" + (Os.isFamily(Os.FAMILY_WINDOWS) ? ".exe" : "");
1071-
10721034
String javaHome = System.getProperty("java.home");
10731035
File javacExe;
1036+
10741037
if (Os.isName("AIX")) {
10751038
javacExe = new File(javaHome + File.separator + ".." + File.separator + "sh", javacCommand);
10761039
} else if (Os.isName("Mac OS X")) {
@@ -1092,7 +1055,6 @@ private static String getJavacExecutable() throws IOException {
10921055
throw new IOException("The environment variable JAVA_HOME=" + javaHome
10931056
+ " doesn't exist or is not a valid directory.");
10941057
}
1095-
10961058
javacExe = new File(env.getProperty("JAVA_HOME") + File.separator + "bin", javacCommand);
10971059
}
10981060

0 commit comments

Comments
 (0)