use of com.redhat.ceylon.compiler.java.launcher.Main in project ceylon-compiler by ceylon.
the class CeyloncTool method getTask.
public CeyloncTaskImpl getTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits) {
// final String kindMsg = "All compilation units must be of SOURCE kind";
if (options != null)
for (String option : options) // null check
option.getClass();
if (classes != null) {
for (String cls : classes) if (// implicit null check
!SourceVersion.isName(cls) && // FIX for ceylon because default is not a valid name for Java
!"default".equals(cls))
throw new IllegalArgumentException("Not a valid class name: " + cls);
}
if (fileManager == null)
fileManager = getStandardFileManager(out, diagnosticListener, null, null);
Context context = ((CeyloncFileManager) fileManager).getContext();
if (diagnosticListener != null && context.get(DiagnosticListener.class) == null)
context.put(DiagnosticListener.class, diagnosticListener);
context.put(JavaFileManager.class, fileManager);
JavacTool.processOptions(context, fileManager, options);
Main compiler = new Main("ceyloncTask", context.get(Log.outKey));
return new CeyloncTaskImpl(compiler, options, context, classes, compilationUnits);
}
use of com.redhat.ceylon.compiler.java.launcher.Main in project ceylon-compiler by ceylon.
the class CeylonCompileTool method initialize.
@Override
public void initialize(CeylonTool mainTool) throws IOException {
compiler = new Main("ceylon compile");
Options options = Options.instance(new Context());
if (modulesOrFiles.isEmpty() && !javac.contains("-help") && !javac.contains("-X") && !javac.contains("-version")) {
throw new IllegalStateException("Argument moduleOrFile should appear at least 1 time(s)");
}
arguments = new ArrayList<>();
if (cwd != null) {
arguments.add("-cwd");
arguments.add(cwd.getPath());
}
for (File source : applyCwd(this.sources)) {
arguments.add("-src");
arguments.add(source.getPath());
options.addMulti(OptionName.SOURCEPATH, source.getPath());
}
for (File resource : applyCwd(this.resources)) {
arguments.add("-res");
arguments.add(resource.getPath());
//options.addMulti(OptionName.RESOURCEPATH, resource.getPath());
}
if (resourceRoot != null) {
arguments.add("-resroot");
arguments.add(resourceRoot);
}
if (continueOnErrors) {
arguments.add("-continue");
}
if (progress) {
arguments.add("-progress");
}
if (offline) {
arguments.add("-offline");
}
if (timeout != -1) {
arguments.add("-timeout");
arguments.add(String.valueOf(timeout));
}
if (flatClasspath) {
arguments.add("-flat-classpath");
}
if (autoExportMavenDependencies) {
arguments.add("-auto-export-maven-dependencies");
}
if (overrides != null) {
arguments.add("-overrides");
if (overrides.startsWith("classpath:")) {
arguments.add(overrides);
} else {
arguments.add(applyCwd(new File(overrides)).getPath());
}
}
if (noOsgi) {
arguments.add("-noosgi");
}
if (osgiProvidedBundles != null && !osgiProvidedBundles.isEmpty()) {
arguments.add("-osgi-provided-bundles");
arguments.add(osgiProvidedBundles);
}
if (noPom) {
arguments.add("-nopom");
}
if (pack200) {
arguments.add("-pack200");
}
if (verbose != null) {
if (verbose.isEmpty()) {
arguments.add("-verbose");
} else {
arguments.add("-verbose:" + verbose);
}
}
if (out != null) {
arguments.add("-out");
arguments.add(out);
}
if (user != null) {
arguments.add("-user");
arguments.add(user);
}
if (pass != null) {
arguments.add("-pass");
arguments.add(pass);
}
String fileEncoding = encoding;
if (fileEncoding == null) {
fileEncoding = DefaultToolOptions.getDefaultEncoding();
}
if (fileEncoding != null) {
JavacOption encodingOpt = getJavacOpt(OptionName.ENCODING.toString());
validateWithJavac(options, encodingOpt, OptionName.ENCODING.toString(), fileEncoding, "option.error.syntax.encoding");
arguments.add(OptionName.ENCODING.toString());
arguments.add(fileEncoding);
}
if (systemRepo != null) {
arguments.add("-sysrep");
arguments.add(systemRepo);
}
if (cacheRepo != null) {
arguments.add("-cacherep");
arguments.add(cacheRepo);
}
if (noDefRepos) {
arguments.add("-nodefreps");
}
if (repo != null) {
for (URI uri : this.repo) {
arguments.add("-rep");
arguments.add(uri.toString());
}
}
if (suppressWarnings != null) {
arguments.add("-suppress-warnings");
arguments.add(EnumUtil.enumsToString(suppressWarnings));
}
addJavacArguments(arguments);
List<File> srcs = applyCwd(this.sources);
List<String> expandedModulesOrFiles = ModuleWildcardsHelper.expandWildcards(srcs, this.modulesOrFiles, Backend.Java);
if (expandedModulesOrFiles.isEmpty()) {
throw new ToolUsageError("No modules or source files to compile");
}
JavacOption sourceFileOpt = getJavacOpt(OptionName.SOURCEFILE.toString());
if (sourceFileOpt != null) {
for (String moduleOrFile : expandedModulesOrFiles) {
validateWithJavac(options, sourceFileOpt, moduleOrFile, moduleOrFile, "argument.error");
}
}
validateSourceArguments(expandedModulesOrFiles);
arguments.addAll(expandedModulesOrFiles);
if (verbose != null) {
System.out.println(arguments);
System.out.flush();
}
}
Aggregations