Skip to content

Commit 2bfcdbd

Browse files
fjalvingholamy
authored andcommitted
Add extra compiler parameters when specified. Remove all debug output.
1 parent 9a983da commit 2bfcdbd

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import java.util.LinkedHashMap;
6363
import java.util.List;
6464
import java.util.Map;
65+
import java.util.Map.Entry;
6566
import java.util.Properties;
6667
import java.util.Set;
6768
import java.util.StringTokenizer;
@@ -190,6 +191,17 @@ public CompilerResult performCompile( CompilerConfiguration config )
190191
if(! propFile.exists() || ! propFile.isFile())
191192
throw new IllegalArgumentException("Properties file " + propFile + " does not exist");
192193
}
194+
195+
for(Entry<String, String> entry : extras.entrySet()) {
196+
String opt = entry.getKey();
197+
if(! opt.startsWith("-"))
198+
opt = "-" + opt; // This is beyond sad
199+
args.add(opt);
200+
String value = entry.getValue();
201+
if(null != value && ! value.isEmpty())
202+
args.add(value);
203+
}
204+
193205
//settings.putAll( extras );
194206

195207
//if ( settings.containsKey( "properties" ) )
@@ -220,9 +232,12 @@ public CompilerResult performCompile( CompilerConfiguration config )
220232
// }
221233
//}
222234

235+
// Output path
236+
args.add("-d");
237+
args.add(config.getOutputLocation());
238+
223239
// Annotation processors defined?
224240
List<String> extraSourceDirs = new ArrayList<>();
225-
226241
if(!isPreJava16(config)) {
227242
//now add jdk 1.6 annotation processing related parameters
228243
String[] annotationProcessors = config.getAnnotationProcessors();
@@ -247,27 +262,26 @@ public CompilerResult performCompile( CompilerConfiguration config )
247262
File generatedSourcesDir = config.getGeneratedSourcesDirectory();
248263
if(generatedSourcesDir != null) {
249264
generatedSourcesDir.mkdirs();
265+
extraSourceDirs.add(generatedSourcesDir.getAbsolutePath());
266+
267+
//-- option to specify where annotation processor is to generate its output
268+
args.add("-s");
269+
args.add(generatedSourcesDir.getAbsolutePath());
250270
}
251271
if(config.getProc() != null) {
252272
args.add("-proc:" + config.getProc());
253273
}
254-
extraSourceDirs.add(generatedSourcesDir.getAbsolutePath());
255274
}
256275
}
257276

258-
// Output path
259-
args.add("-d");
260-
args.add(config.getOutputLocation());
261-
262277
//-- Write .class files even when error occur, but make sure methods with compile errors do abort when called
263278
//args.add("-proceedOnError:Fatal"); probably not a good plan as it will cause incremental compile to not work
264279

265280
//-- classpath
266-
List<String> classpathEntries = config.getClasspathEntries();
267-
if(classpathEntries.size() != 0) {
268-
args.add("-classpath");
269-
args.add(getPathString(classpathEntries));
270-
}
281+
List<String> classpathEntries = new ArrayList<>(config.getClasspathEntries());
282+
classpathEntries.add(config.getOutputLocation());
283+
args.add("-classpath");
284+
args.add(getPathString(classpathEntries));
271285

272286
// ----------------------------------------------------------------------
273287
// Compile!
@@ -298,13 +312,13 @@ public CompilerResult performCompile( CompilerConfiguration config )
298312
return new CompilerResult(true, Collections.EMPTY_LIST);
299313
}
300314

301-
System.out.println(">>>> ECJ: " + args);
315+
//System.out.println(">>>> ECJ: " + args);
302316

303317
StringWriter sw = new StringWriter();
304318
PrintWriter devNull = new PrintWriter(sw);
305319

306320
//BatchCompiler.compile(args.toArray(new String[args.size()]), new PrintWriter(System.err), new PrintWriter(System.out), new CompilationProgress() {
307-
boolean worked = BatchCompiler.compile(args.toArray(new String[args.size()]), devNull, devNull, new CompilationProgress() {
321+
BatchCompiler.compile(args.toArray(new String[args.size()]), devNull, devNull, new CompilationProgress() {
308322
@Override public void begin(int i) {
309323

310324
}
@@ -330,10 +344,6 @@ public CompilerResult performCompile( CompilerConfiguration config )
330344
boolean hasError = false;
331345
if(errorF.length() < 80) {
332346
throw new IOException("Failed to run the ECJ compiler:\n" + sw.toString());
333-
//messageList = new ArrayList<>();
334-
//messageList.add(new CompilerMessage("Internal compiler error"));
335-
//System.err.println(">> " + sw.toString());
336-
//return new CompilerResult(false, messageList);
337347
}
338348
messageList = new EcjResponseParser().parse(errorF, errorsAsWarnings);
339349

@@ -348,11 +358,11 @@ public CompilerResult performCompile( CompilerConfiguration config )
348358
} catch(Exception x) {
349359
throw new RuntimeException(x); // sigh
350360
} finally {
351-
//if(null != errorF) {
352-
//try {
353-
// errorF.delete();
354-
// } catch(Exception x) {}
355-
//}
361+
if(null != errorF) {
362+
try {
363+
errorF.delete();
364+
} catch(Exception x) {}
365+
}
356366
}
357367
}
358368

0 commit comments

Comments
 (0)