use of org.codehaus.groovy.tools.FileSystemCompiler in project groovy by apache.
the class Groovyc method extractJointOptions.
/**
* If {@code groovyc} task includes a nested {@code javac} task, check for
* shareable configuration. {@code FileSystemCompiler} supports several
* command-line arguments for configuring joint compilation:
* <ul>
* <li><tt>-j</tt> enables joint compile
* <li><tt>-F</tt> is used to pass flags
* <li><tt>-J</tt> is used to pass name=value pairs
* </ul>
* Joint compilation options are transferred from {@link FileSystemCompiler}
* to {@link CompilerConfiguration}'s jointCompileOptions property. Flags
* are saved to key "flags" (with the inclusion of "parameters" if enabled
* on groovyc), pairs are saved to key "namedValues" and the key "memStub"
* may also be set to {@link Boolean#TRUE} to influence joint compilation.
*
* @see org.codehaus.groovy.tools.javac.JavacJavaCompiler
* @see javax.tools.JavaCompiler
*/
private List<String> extractJointOptions(Path classpath) {
List<String> jointOptions = new ArrayList<>();
if (!jointCompilation)
return jointOptions;
// map "debug" and "debuglevel" to "-Fg"
if (javac.getDebug()) {
jointOptions.add("-Fg" + Optional.ofNullable(javac.getDebugLevel()).map(level -> ":" + level).orElse(""));
} else {
jointOptions.add("-Fg:none");
}
// map "deprecation" to "-Fdeprecation"
if (javac.getDeprecation()) {
jointOptions.add("-Fdeprecation");
}
// map "nowarn" to "-Fnowarn"
if (javac.getNowarn()) {
jointOptions.add("-Fnowarn");
}
// map "verbose" to "-Fverbose"
if (javac.getVerbose()) {
jointOptions.add("-Fverbose");
}
RuntimeConfigurable rc = javac.getRuntimeConfigurableWrapper();
for (Map.Entry<String, Object> e : rc.getAttributeMap().entrySet()) {
String key = e.getKey();
if (key.equals("depend") || key.equals("encoding") || key.equals("extdirs") || key.equals("nativeheaderdir") || key.equals("release") || key.equals("source") || key.equals("target")) {
switch(key) {
case "nativeheaderdir":
key = "h";
break;
case "release":
// to get "--" when passed to javac
key = "-" + key;
break;
default:
}
// map "depend", "encoding", etc. to "-Jkey=val"
jointOptions.add("-J" + key + "=" + getProject().replaceProperties(e.getValue().toString()));
} else if (key.contains("classpath")) {
if (key.startsWith("boot")) {
// map "bootclasspath" or "bootclasspathref" to "-Jbootclasspath="
jointOptions.add("-Jbootclasspath=" + javac.getBootclasspath());
} else {
// map "classpath" or "classpathref" to "--classpath"
classpath.add(javac.getClasspath());
}
} else if (key.contains("module") && key.contains("path")) {
if (key.startsWith("upgrade")) {
// map "upgrademodulepath" or "upgrademodulepathref" to "-J-upgrade-module-path="
jointOptions.add("-J-upgrade-module-path=" + javac.getUpgrademodulepath());
} else if (key.contains("source")) {
// map "modulesourcepath" or "modulesourcepathref" to "-J-module-source-path="
jointOptions.add("-J-module-source-path=" + javac.getModulesourcepath());
} else {
// map "modulepath" or "modulepathref" to "-J-module-path="
jointOptions.add("-J-module-path=" + javac.getModulepath());
}
} else if (!key.contains("debug") && !key.equals("deprecation") && !key.equals("nowarn") && !key.equals("verbose")) {
log.warn("The option " + key + " cannot be set on the contained <javac> element. The option will be ignored.");
}
// TODO: defaultexcludes, excludes(file)?, includes(file)?, includeDestClasses, tempdir
}
// can be multiple of them) for additional options to be passed to javac.
for (RuntimeConfigurable childrc : Collections.list(rc.getChildren())) {
if (childrc.getElementTag().equals("compilerarg")) {
for (Map.Entry<String, Object> e : childrc.getAttributeMap().entrySet()) {
String key = e.getKey();
if (key.equals("value")) {
String value = getProject().replaceProperties(e.getValue().toString());
StringTokenizer st = new StringTokenizer(value, " ");
while (st.hasMoreTokens()) {
String option = st.nextToken();
// GROOVY-5063: map "-Werror", etc. to "-FWerror"
jointOptions.add(option.replaceFirst("^-(W|X|proc:)", "-F$1"));
}
}
}
}
}
return jointOptions;
}
use of org.codehaus.groovy.tools.FileSystemCompiler in project freeplane by freeplane.
the class ScriptCompiler method compile.
private static void compile(File dir, File[] files) {
try {
final CompilerConfiguration compilerConfiguration = GroovyScript.createCompilerConfiguration();
compilerConfiguration.setTargetDirectory(dir);
final CompilationUnit unit = new CompilationUnit(compilerConfiguration, null, new GroovyClassLoader(ScriptingEngine.class.getClassLoader()));
new FileSystemCompiler(compilerConfiguration, unit).compile(files);
LogUtils.info("compiled in " + dir + ": " + createNameList(files));
} catch (Exception e) {
LogUtils.severe("error compiling in " + dir + createNameList(files), e);
}
}
Aggregations