/
SarlBatchCompiler.java
2402 lines (2184 loc) · 75.4 KB
/
SarlBatchCompiler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2019 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.sarl.lang.compiler.batch;
import java.io.Closeable;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import javax.inject.Provider;
import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import com.google.inject.ImplementedBy;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtend.core.macro.ProcessorInstanceForJvmTypeProvider;
import org.eclipse.xtext.Constants;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider;
import org.eclipse.xtext.common.types.access.impl.IndexedJvmTypeAccess;
import org.eclipse.xtext.common.types.descriptions.IStubGenerator;
import org.eclipse.xtext.diagnostics.Severity;
import org.eclipse.xtext.generator.GeneratorContext;
import org.eclipse.xtext.generator.GeneratorDelegate;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IOutputConfigurationProvider;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
import org.eclipse.xtext.generator.OutputConfiguration;
import org.eclipse.xtext.generator.OutputConfigurationAdapter;
import org.eclipse.xtext.mwe.NameBasedFilter;
import org.eclipse.xtext.mwe.PathTraverser;
import org.eclipse.xtext.parser.IEncodingProvider;
import org.eclipse.xtext.resource.CompilerPhases;
import org.eclipse.xtext.resource.FileExtensionProvider;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.resource.persistence.StorageAwareResource;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.util.Files;
import org.eclipse.xtext.util.JavaVersion;
import org.eclipse.xtext.util.Strings;
import org.eclipse.xtext.util.UriUtil;
import org.eclipse.xtext.util.internal.AlternateJdkLoader;
import org.eclipse.xtext.validation.CheckMode;
import org.eclipse.xtext.validation.IResourceValidator;
import org.eclipse.xtext.validation.Issue;
import org.eclipse.xtext.workspace.FileProjectConfig;
import org.eclipse.xtext.workspace.ProjectConfigAdapter;
import org.eclipse.xtext.xbase.compiler.GeneratorConfig;
import org.eclipse.xtext.xbase.compiler.GeneratorConfigProvider;
import org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider;
import org.eclipse.xtext.xbase.lib.Inline;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.resource.BatchLinkableResource;
import org.eclipse.xtext.xbase.resource.BatchLinkableResourceStorageWritable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.sarl.lang.SARLConfig;
import io.sarl.lang.compiler.GeneratorConfig2;
import io.sarl.lang.compiler.GeneratorConfigProvider2;
import io.sarl.lang.compiler.IGeneratorConfigProvider2;
import io.sarl.lang.compiler.batch.InternalXtextLogger.InternalXtextLoggerFactory;
import io.sarl.lang.extralanguage.IExtraLanguageContribution;
import io.sarl.lang.extralanguage.IExtraLanguageContributions;
import io.sarl.lang.util.Utils;
import io.sarl.lang.validation.IConfigurableIssueSeveritiesProvider;
/** The compiler from SARL that could be used for batch tasks (Maven, CLI).
*
* <p>This compiler is inspired by the Xtend batch compiler.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.5
*/
@SuppressWarnings({"checkstyle:classfanoutcomplexity", "checkstyle:methodcount", "checkstyle:classdataabstractioncoupling"})
public class SarlBatchCompiler {
private static final String BINCLASS_FOLDER_PREFIX = "classes"; //$NON-NLS-1$
private static final String STUB_FOLDER_PREFIX = "stubs"; //$NON-NLS-1$
private static final String INTERNAL_ERROR_CODE = SarlBatchCompiler.class.getName() + ".internal_error"; //$NON-NLS-1$
private static final FileFilter ACCEPT_ALL_FILTER = new FileFilter() {
@Override
public boolean accept(File pathname) {
return true;
}
};
private static final Predicate<IExtraLanguageContribution> DISABLER = it -> false;
private static Class<? extends IJavaBatchCompiler> defaultJavaBatchCompiler;
/** The provider of resource sets.
*/
protected Provider<ResourceSet> resourceSetProvider;
private File outputPath;
private File classOutputPath;
private File tempPath;
private boolean deleteTempPath = true;
private List<File> bootClasspath;
private List<File> classpath;
private String encoding;
private boolean writeTraceFiles = true;
private boolean writeStorageFiles = true;
private boolean verbose;
private boolean enableJavaPostCompilation;
private List<File> sourcePath;
private boolean useCurrentClassLoaderAsParent;
private org.eclipse.emf.common.util.URI baseUri;
private FileProjectConfig projectConfig;
private Map<String, OutputConfiguration> outputConfigurations;
private ClassLoader currentClassLoader;
private ClassLoader jvmTypesClassLoader;
private ClassLoader annotationProcessingClassLoader;
@Inject
private IGeneratorConfigProvider generatorConfigProvider;
@Inject
private IGeneratorConfigProvider2 generatorConfigProvider2;
@Inject
private IOutputConfigurationProvider outputConfigurationProvider;
@Inject
private CompilerPhases compilerPhases;
@Inject
private Provider<JavaIoFileSystemAccess> javaIoFileSystemAccessProvider;
@Inject
private IndexedJvmTypeAccess indexedJvmTypeAccess;
@Inject
private IEncodingProvider.Runtime encodingProvider;
@Inject
private FileExtensionProvider fileExtensionProvider;
@Inject
private IResourceDescription.Manager resourceDescriptionManager;
@Inject
private IStubGenerator stubGenerator;
@Inject
private GeneratorDelegate generator;
@Inject
private IConfigurableIssueSeveritiesProvider issueSeverityProvider;
@Inject
private IExtraLanguageContributions extraLanguageContributions;
@Inject
@Named(Constants.LANGUAGE_NAME)
private String languageName;
private IJavaBatchCompiler javaCompiler;
private Logger logger;
private IssueMessageFormatter messageFormatter;
private Collection<IssueMessageListener> messageListeners = new LinkedList<>();
private Collection<ICompilatedResourceReceiver> resourceReceivers = new LinkedList<>();
private final List<File> tempFolders = new ArrayList<>();
private Comparator<Issue> issueComparator = new DefaultIssueComparator();
private GeneratorConfig currentGeneratorConfiguration;
private GeneratorConfig2 currentGeneratorConfiguration2;
private String enabledExtraLanguageContributions;
private boolean reportInternalProblemsAsIssues;
private OptimizationLevel optimizationLevel;
/** Constructor the batch compiler.
*/
public SarlBatchCompiler() {
this.logger = LoggerFactory.getLogger(getClass());
}
/** Change the Java compiler.
*
* @param compiler the Java compiler
* @since 0.8
*/
@Inject
public void setJavaCompiler(IJavaBatchCompiler compiler) {
assert compiler != null;
this.javaCompiler = compiler;
}
/** Create a default Java batch compiler, without injection.
*
* @return the Java batch compiler.
* @since 0.8
*/
public static IJavaBatchCompiler newDefaultJavaBatchCompiler() {
try {
synchronized (SarlBatchCompiler.class) {
if (defaultJavaBatchCompiler == null) {
final ImplementedBy annotation = IJavaBatchCompiler.class.getAnnotation(ImplementedBy.class);
assert annotation != null;
final Class<?> type = annotation.value();
assert type != null;
defaultJavaBatchCompiler = type.asSubclass(IJavaBatchCompiler.class);
}
return defaultJavaBatchCompiler.newInstance();
}
} catch (Exception exception) {
throw new RuntimeException(exception);
}
}
/** Replies the Java compiler.
*
* @return the Java compiler
* @since 0.8
*/
public IJavaBatchCompiler getJavaCompiler() {
if (this.javaCompiler == null) {
this.javaCompiler = newDefaultJavaBatchCompiler();
}
return this.javaCompiler;
}
/** Change the optimization level that should be applied to the generated Java byte code.
*
* @param level the optimization level.
* @since 0.8
*/
public void setOptimizationLevel(OptimizationLevel level) {
this.optimizationLevel = level;
}
/** Replies the optimization level that should be applied to the generated Java byte code.
*
* @return the optimization level.
* @since 0.8
*/
public OptimizationLevel getOptimizationLevel() {
if (this.optimizationLevel == null) {
this.optimizationLevel = OptimizationLevel.getDefault();
}
return this.optimizationLevel;
}
/** Change the flag that permits to report the compiler's internal problems as issues.
*
* @param reportAsIssues {@code true} if the internal errors are reported as issues.
* @since 0.8
* @see #addIssueMessageListener(IssueMessageListener)
*/
public void setReportInternalProblemsAsIssues(boolean reportAsIssues) {
this.reportInternalProblemsAsIssues = reportAsIssues;
}
/** Replies the flag that indicates to report the compiler's internal problems as issues.
*
* @return {@code true} if the internal errors are reported as issues.
* @since 0.8
* @see #addIssueMessageListener(IssueMessageListener)
*/
public boolean getReportInternalProblemsAsIssues() {
return this.reportInternalProblemsAsIssues;
}
/** Change the extra languages' generators that should be enabled.
*
* @param identifiers the identifier, the identifiers (separated by {@link File#pathSeparator} of the
* extra languages' generator(s) to be enabled. If this parameter is {@code null}, all the extra
* languages' generator are disabled.
* @since 0.8
*/
public void setExtraLanguageGenerators(String identifiers) {
this.enabledExtraLanguageContributions = Strings.emptyIfNull(identifiers);
}
/** Replies the extra languages' generators that should be enabled.
*
* @return the identifier, the identifiers (separated by {@link File#pathSeparator} of the
* extra languages' generator(s) to be enabled. If this parameter is {@code null}, all the extra
* languages' generator are disabled.
* @since 0.8
*/
public String getExtraLanguageGenerators() {
return this.enabledExtraLanguageContributions;
}
/** Set the comparator of issues that is used for sorting the issues before they are logged.
*
* @param comparator the comparator; never <code>null</code>.
*/
public void setIssueComparator(Comparator<Issue> comparator) {
if (comparator != null) {
this.issueComparator = comparator;
}
}
/** Replies the comparator of issues that is used for sorting the issues before they are logged.
*
* @return the comparator; never <code>null</code>.
*/
public Comparator<Issue> getIssueComparator() {
return this.issueComparator;
}
/** Replies if the Java compiler should be invoked after the SARL compiler is invoked.
*
* @return <code>true</code> if the Java compiler is invoked after the SARL compiler.
*/
public boolean isJavaPostCompilationEnable() {
return this.enableJavaPostCompilation;
}
/** Set if the Java compiler should be invoked after the SARL compiler is invoked.
*
* @param enable <code>true</code> if the Java compiler is invoked after the SARL compiler.
*/
public void setJavaPostCompilationEnable(boolean enable) {
this.enableJavaPostCompilation = enable;
}
/** Replies the formatter of the issue messages.
*
* @return the formatter.
*/
public IssueMessageFormatter getIssueMessageFormatter() {
return this.messageFormatter;
}
/** Set the formatter of the issue messages.
*
* @param formatter the formatter.
*/
public void setIssueMessageFormatter(IssueMessageFormatter formatter) {
this.messageFormatter = formatter;
}
/** Add a listener on the issue messages.
*
* @param listener the listener.
* @since 0.6
*/
public void addIssueMessageListener(IssueMessageListener listener) {
this.messageListeners.add(listener);
}
/** Add a listener on the issue messages.
*
* @param listener the listener.
* @since 0.6
*/
public void removeIssueMessageListener(IssueMessageListener listener) {
this.messageListeners.remove(listener);
}
/** Replies the message for the given issue.
*
* @param issue the issue.
* @param uri URI to the problem.
* @param message the formatted message.
* @since 0.6
*/
private void notifiesIssueMessageListeners(Issue issue, org.eclipse.emf.common.util.URI uri, String message) {
for (final IssueMessageListener listener : this.messageListeners) {
listener.onIssue(issue, uri, message);
}
}
/** Add a receiver on the successfully compiled resources.
*
* @param receiver the receiver.
* @since 0.6
*/
public void addCompiledResourceReceiver(ICompilatedResourceReceiver receiver) {
this.resourceReceivers.add(receiver);
}
/** Remove a receiver on the successfully compiled resources.
*
* @param receiver the receiver.
* @since 0.6
*/
public void removeCompiledResourceReceiver(ICompilatedResourceReceiver receiver) {
this.resourceReceivers.remove(receiver);
}
/** Replies the message for the given issue.
*
* @param resource the compiled resource.
* @since 0.6
*/
private void notifiesCompiledResourceReceiver(Resource resource) {
for (final ICompilatedResourceReceiver receiver : this.resourceReceivers) {
receiver.receiveCompiledResource(resource);
}
}
/** Replies the logger.
*
* @return the logger.
*/
public Logger getLogger() {
return this.logger;
}
/** Set the logger.
*
* @param logger the logger.
*/
public void setLogger(Logger logger) {
this.logger = logger == null ? LoggerFactory.getLogger(getClass()) : logger;
}
/** Set the provider of resource sets.
*
* @param resourceSetProvider the provider.
*/
@Inject
public void setResourceSetProvider(Provider<ResourceSet> resourceSetProvider) {
this.resourceSetProvider = resourceSetProvider;
}
private static File normalizeFile(String file) {
return new File(new File(file).getAbsoluteFile().toURI().normalize());
}
/** Replies if the trace files must be generated.
*
* <p>A trace file contains the links between the class, java and SARL files.
* They are mandatory for retreiving and displaying the SARL source code from
* a JVM element.
*
* <p>The usual filename for the trace files follows the pattern
* {@code .Type.java._trace}, where {@code Type} is the name of the SARL type declaration.
*
* @return <code>true</code> for generation.
*/
public boolean isWriteTraceFiles() {
return this.writeTraceFiles;
}
/** Set if the trace files must be generated.
*
* <p>A trace file contains the links between the class, java and SARL files.
* They are mandatory for retreiving and displaying the SARL source code from
* a JVM element.
*
* <p>The usual filename for the trace files follows the pattern
* {@code .Type.java._trace}, where {@code Type} is the name of the SARL type declaration.
*
* @param writeTraceFiles <code>true</code> for generation.
*/
public void setWriteTraceFiles(boolean writeTraceFiles) {
this.writeTraceFiles = writeTraceFiles;
}
/** Replies if the storage files must be generated.
*
* <p>The storage files are binary versions of the resources in order
* to have faster reading/accessing.
*
* <p>The usual filename for the storage files follows the pattern
* {@code .Type.sarlbin}, where {@code Type} is the name of the SARL type declaration.
*
* @return <code>true</code> for generation.
*/
@Pure
public boolean isWriteStorageFiles() {
return this.writeStorageFiles;
}
/** Set if the storage files must be generated.
*
* <p>The storage files are binary versions of the resources in order
* to have faster reading/accessing.
*
* <p>The usual filename for the storage files follows the pattern
* {@code .Type.sarlbin}, where {@code Type} is the name of the SARL type declaration.
*
* @param writeStorageFiles <code>true</code> for generation.
*/
public void setWriteStorageFiles(boolean writeStorageFiles) {
this.writeStorageFiles = writeStorageFiles;
}
/** Replies if the compiler is verbose.
*
* @return <code>true</code> if the compiler is verbose.
*/
@Pure
public boolean isJavaCompilerVerbose() {
return this.verbose;
}
/** Set the underlying Java compiler verbosity.
*
* @param verbose <code>true</code> if the Java compiler is verbose.
*/
public void setJavaCompilerVerbose(boolean verbose) {
this.verbose = verbose;
}
/** Replies the current class loader.
*
* @return the class loader.
*/
@Pure
public ClassLoader getCurrentClassLoader() {
if (this.currentClassLoader == null) {
this.currentClassLoader = getClass().getClassLoader();
}
return this.currentClassLoader;
}
/** Set the current class loader.
*
* @param loader the new current class loader.
*/
public void setCurrentClassLoader(ClassLoader loader) {
this.currentClassLoader = null;
}
/** Set if the class loaderr of this batch compiler must be used as sthe parent class loader.
*
* @param useCurrentClassLoaderAsParent <code>true</code> for using the class loader of this batch compiler.
*/
public void setUseCurrentClassLoaderAsParent(boolean useCurrentClassLoaderAsParent) {
this.useCurrentClassLoaderAsParent = useCurrentClassLoaderAsParent;
}
/** Replies if the class loaderr of this batch compiler must be used as sthe parent class loader.
*
* @return <code>true</code> for using the class loader of this batch compiler.
*/
@Pure
public boolean isUseCurrentClassLoaderAsParent() {
return this.useCurrentClassLoaderAsParent;
}
/** Change the base path.
*
* @param basePath the base path.
*/
public void setBasePath(String basePath) {
setBaseURI(UriUtil.createFolderURI(normalizeFile(basePath)));
}
/** Change the base URI.
*
* @param basePath the base path.
*/
public void setBaseURI(org.eclipse.emf.common.util.URI basePath) {
this.baseUri = basePath;
}
/** Change the path where the Java files are generated.
*
* @param path the path, or <code>null</code> for using the default path in {@link SARLConfig#FOLDER_SOURCE_GENERATED}..
*/
public void setOutputPath(File path) {
this.outputPath = path;
}
/** Change the path where the Java files are generated.
*
* @param path the path.
*/
public void setOutputPath(String path) {
setOutputPath(normalizeFile(path));
}
/** Replies the path where the Java files are generated.
*
* @return the path; or <code>null</code> for using the default path in {@link SARLConfig#FOLDER_SOURCE_GENERATED}.
*/
@Pure
public File getOutputPath() {
return this.outputPath;
}
/** Replies the path where the class files are generated.
*
* @return the path; or <code>null</code> for ignoring the class generation.
*/
@Pure
public File getClassOutputPath() {
return this.classOutputPath;
}
/** Set the path where the class files are generated.
*
* @param path the path; or <code>null</code> for ignoring the class generation.
*/
@Pure
public void setClassOutputPath(File path) {
this.classOutputPath = path;
}
/** Change the boot classpath.
* This option is only supported on JDK 8 and older and will be ignored when source level is 9 or newer.
*
* <p>The boot classpath is a list the names of folders or jar files that are separated by {@link File#pathSeparator}.
*
* @param bootClasspath the new boot classpath.
* @see "https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html"
*/
public void setBootClassPath(String bootClasspath) {
final JavaVersion version = JavaVersion.fromQualifier(getJavaSourceVersion());
if (version.isAtLeast(JavaVersion.JAVA9)) {
reportInternalWarning(MessageFormat.format(Messages.SarlBatchCompiler_63, bootClasspath));
}
if (Strings.isEmpty(bootClasspath)) {
this.bootClasspath = null;
} else {
this.bootClasspath = new ArrayList<>();
for (final String path : Strings.split(bootClasspath, File.pathSeparator)) {
this.bootClasspath.add(normalizeFile(path));
}
}
}
/** Change the boot classpath.
* This option is only supported on JDK 8 and older and will be ignored when source level is 9 or newer.
*
* @param bootClasspath the new boot classpath.
* @see "https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html"
*/
public void setBootClassPath(Collection<File> bootClasspath) {
final JavaVersion version = JavaVersion.fromQualifier(getJavaSourceVersion());
if (version.isAtLeast(JavaVersion.JAVA9)) {
reportInternalWarning(MessageFormat.format(Messages.SarlBatchCompiler_63,
Joiner.on(File.pathSeparator).join(bootClasspath)));
}
if (bootClasspath == null || bootClasspath.isEmpty()) {
this.bootClasspath = null;
} else {
this.bootClasspath = new ArrayList<>(bootClasspath);
}
}
/** Replies the boot classpath.
* This option is only supported on JDK 8 and older and will be ignored when source level is 9 or newer.
*
* @return the boot classpath.
* @see "https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html"
*/
@Pure
public List<File> getBootClassPath() {
if (this.bootClasspath == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(this.bootClasspath);
}
/** Change the classpath.
*
* <p>The classpath is a list the names of folders or jar files that are separated by {@link File#pathSeparator}.
*
* @param classpath the new classpath.
*/
public void setClassPath(String classpath) {
this.classpath = new ArrayList<>();
for (final String path : Strings.split(classpath, File.pathSeparator)) {
this.classpath.add(normalizeFile(path));
}
}
/** Change the classpath.
*
* @param classpath the new classpath.
*/
public void setClassPath(Collection<File> classpath) {
this.classpath = new ArrayList<>(classpath);
}
/** Replies the classpath.
*
* @return the classpath.
*/
@Pure
public List<File> getClassPath() {
if (this.classpath == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(this.classpath);
}
/** Change the path where the Xtext stubs are generated.
*
* @param path the path.
*/
public void setTempDirectory(File path) {
this.tempPath = path;
}
/** Change the path where the Xtext stubs are generated.
*
* @param path the path.
*/
public void setTempDirectory(String path) {
setTempDirectory(normalizeFile(path));
}
/** Replies the path where the Xtext stubs are generated.
*
* @return the path; or <code>null</code> for using the default path.
*/
@Pure
public File getTempDirectory() {
if (this.tempPath == null) {
this.tempPath = createTempDirectory();
}
return this.tempPath;
}
/** Create the temp directory that should be used by the compiler.
*
* @return the temp directory, never {@code null}.
*/
@SuppressWarnings("static-method")
protected File createTempDirectory() {
final File tmpPath = new File(System.getProperty("java.io.tmpdir")); //$NON-NLS-1$
int i = 0;
File tmp = new File(tmpPath, "sarlc" + i); //$NON-NLS-1$
while (tmp.exists()) {
++i;
tmp = new File(tmpPath, "sarlc" + i); //$NON-NLS-1$
}
return tmp;
}
/** Replies if the temp folder must be deleted at the end of the compilation.
*
* @return <code>true</code> if the temp folder is deleted.
*/
@Pure
public boolean isDeleteTempDirectory() {
return this.deleteTempPath;
}
/** Set if the temp folder must be deleted at the end of the compilation.
*
* @param delete <code>true</code> if the temp folder is deleted.
*/
public void setDeleteTempDirectory(boolean delete) {
this.deleteTempPath = delete;
}
/** Change the file encoding.
*
* @param encoding the encoding, usually <code>UTF-8</code>.
*/
public void setFileEncoding(String encoding) {
this.encoding = encoding;
}
/** Change the file encoding.
*
* @return the file encoding, or <code>null</code> if the default encoding must be used.
*/
@Pure
public String getFileEncoding() {
return this.encoding;
}
/** Replies the current generator config.
*
* @return the generator config.
*/
protected GeneratorConfig getGeneratorConfig() {
if (this.currentGeneratorConfiguration == null) {
this.currentGeneratorConfiguration = this.generatorConfigProvider.get(null);
}
return this.currentGeneratorConfiguration;
}
/** Replies the current generator config v2.
*
* @return the generator config v2.
*/
protected GeneratorConfig2 getGeneratorConfig2() {
if (this.currentGeneratorConfiguration2 == null) {
this.currentGeneratorConfiguration2 = this.generatorConfigProvider2.get(null);
}
return this.currentGeneratorConfiguration2;
}
/** Change the version of the Java source to be used for the generated Java files.
*
* @param version the Java version.
*/
public void setJavaSourceVersion(String version) {
final JavaVersion javaVersion = JavaVersion.fromQualifier(version);
if (javaVersion == null) {
final List<String> qualifiers = new ArrayList<>();
for (final JavaVersion vers : JavaVersion.values()) {
qualifiers.addAll(vers.getAllQualifiers());
}
throw new RuntimeException(MessageFormat.format(
Messages.SarlBatchCompiler_0, version, Joiner.on(Messages.SarlBatchCompiler_1).join(qualifiers)));
}
getGeneratorConfig().setJavaSourceVersion(javaVersion);
}
/** Replies the version of the Java source to be used for the generated Java files.
*
* @return the Java version.
*/
@Pure
public String getJavaSourceVersion() {
return getGeneratorConfig().getJavaSourceVersion().getQualifier();
}
/** Replies the compiler generate the Xbase expressions.
*
* @return <code>true</code> if the compiler generates the expressions
*/
@Pure
public boolean isGenerateExpressions() {
return getGeneratorConfig().isGenerateExpressions();
}
/** Set if the compiler generate the Xbase expressions.
*
* @param generateExpressions <code>true</code> if the compiler generates the expressions
*/
public void setGenerateExpressions(boolean generateExpressions) {
getGeneratorConfig().setGenerateExpressions(generateExpressions);
}
/** Replies the <code>@SuppressWarnings</code> is generated.
*
* @return <code>true</code> if the compiler generates the warning supression annotations.
*/
@Pure
public boolean isGenerateSyntheticSuppressWarnings() {
return getGeneratorConfig().isGenerateSyntheticSuppressWarnings();
}
/** Set if the <code>@SuppressWarnings</code> is generated.
*
* @param generateAnnotations <code>true</code> if the compiler generates the warning supression annotations.
*/
public void setGenerateSyntheticSuppressWarnings(boolean generateAnnotations) {
getGeneratorConfig().setGenerateSyntheticSuppressWarnings(generateAnnotations);
}
/** Replies the <code>@Generated</code> is generated.
*
* @return <code>true</code> if the compiler generates the generated annotations.
*/
@Pure
public boolean isGenerateGeneratedAnnotation() {
return getGeneratorConfig().isGenerateGeneratedAnnotation();
}
/** Set if the <code>@Generated</code> is generated.
*
* @param generateAnnotations <code>true</code> if the compiler generates the generated annotations.
*/
public void setGenerateGeneratedAnnotation(boolean generateAnnotations) {
getGeneratorConfig().setGenerateGeneratedAnnotation(generateAnnotations);
}
/** Replies if the generation date is included in the <code>@Generated</code> annotations.
*
* @return <code>true</code> if the generation date is added.
*/
@Pure
public boolean isIncludeDateInGeneratedAnnotation() {
return getGeneratorConfig().isIncludeDateInGeneratedAnnotation();
}
/** Set if the generation date is included in the <code>@Generated</code> annotations.
*
* @param includeDateInGeneratedAnnotation <code>true</code> if the generation date is added.
*/
public void setIncludeDateInGeneratedAnnotation(boolean includeDateInGeneratedAnnotation) {
getGeneratorConfig().setIncludeDateInGeneratedAnnotation(includeDateInGeneratedAnnotation);
}
/** Replies the comment in the <code>@Generated</code> annnotations.
*
* @return the comment.
*/
@Pure
public String getGeneratedAnnotationComment() {
return getGeneratorConfig().getGeneratedAnnotationComment();
}
/** Set the comment in the <code>@Generated</code> annnotations.
*
* @param comment the comment.
*/
public void setGeneratedAnnotationComment(String comment) {
getGeneratorConfig().setGeneratedAnnotationComment(comment);
}
/** Replies if the <code>@Inline</code> shall be generated.
*
* @return <code>true</code> if annotation shall be generated.
*/
@Pure
public boolean isGenerateInlineAnnotation() {
return getGeneratorConfig2().isGenerateInlineAnnotation();
}
/** Set if the <code>@Inline</code> shall be generated.
*
* @param generateInlineAnnotation <code>true</code> if annotation shall be generated.
*/
public void setGenerateInlineAnnotation(final boolean generateInlineAnnotation) {
getGeneratorConfig2().setGenerateInlineAnnotation(generateInlineAnnotation);