当前位置: 首页>>代码示例>>Java>>正文


Java CompilerConfiguration.setSourceEncoding方法代码示例

本文整理汇总了Java中org.codehaus.groovy.control.CompilerConfiguration.setSourceEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java CompilerConfiguration.setSourceEncoding方法的具体用法?Java CompilerConfiguration.setSourceEncoding怎么用?Java CompilerConfiguration.setSourceEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.groovy.control.CompilerConfiguration的用法示例。


在下文中一共展示了CompilerConfiguration.setSourceEncoding方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadByPath

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
@Override
public void loadByPath(Path path) throws Throwable {
	String id;
	if (Files.isDirectory(path)) {
		id = path.getFileName().toString();
		path = path.resolve("plugin.groovy");
	} else {
		if(path.getFileName().toString().equals("plugin.groovy"))
			id = path.getParent().getFileName().toString();
		else {
			id = path.getFileName().toString();
			id = id.substring(0, id.length() - 7);
		}
	}
	System.setProperty("groovy.grape.report.downloads", "true");
	CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
	compilerConfiguration.setSourceEncoding("UTF-8");
	compilerConfiguration.setScriptBaseClass("info.deskchan.groovy_support.GroovyPlugin");
	compilerConfiguration.setClasspath(path.getParent().toString());
	GroovyShell groovyShell = new GroovyShell(compilerConfiguration);
	Script script = groovyShell.parse(path.toFile());
	GroovyPlugin plugin = (GroovyPlugin) script;
	plugin.setPluginDirPath(path.getParent());
	PluginConfig config = new PluginConfig("Groovy");
	path = path.getParent().resolve("manifest.json");
	config.appendFromJson(path);
	PluginManager.getInstance().initializePlugin(id, plugin, config);
}
 
开发者ID:DeskChan,项目名称:DeskChan,代码行数:29,代码来源:Main.java

示例2: create

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
private GroovyScriptEngine create() {
  // custom the configuration of the compiler
  CompilerConfiguration cc = new CompilerConfiguration();
  cc.setTargetDirectory(new File(applicationDirectories.getTemporaryDirectory(), "groovy-classes"));
  cc.setSourceEncoding("UTF-8");
  cc.addCompilationCustomizers(secureASTCustomizer());
  GroovyClassLoader gcl = new GroovyClassLoader(classLoader, cc);

  engine = new GroovyScriptEngine(gcl);

  // HACK: For testing
  log.info("Created engine: {}", engine);

  return engine;
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:16,代码来源:GroovyScriptEngineFactory.java

示例3: createScenario

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
public static Scenario createScenario(String pathString){
    CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
    compilerConfiguration.setSourceEncoding("UTF-8");
    compilerConfiguration.setScriptBaseClass("info.deskchan.groovy_support.Scenario");
    Path path = Paths.get(pathString);
    compilerConfiguration.setClasspath(path.getParent().toString());
    GroovyShell groovyShell = new GroovyShell(compilerConfiguration);
    List<String> scriptLines = null;
    try {
        scriptLines = Files.readAllLines(path, Charset.forName("UTF-8"));
    } catch (Exception e){
        pluginProxy.log("Invalid path specified for scenario");
        return null;
    }
    StringBuilder scriptText = new StringBuilder();
    String[] buffers = new String[1];
    for(int u=0; u<buffers.length; u++) buffers[u] = null;
    for(int i = 0; i<scriptLines.size(); i++){
        String line = scriptLines.get(i).trim();
        switch (line.charAt(0)){
            case '<':
                scriptLines.set(i, line.substring(1).trim()+" = receive()");
                break;
            case '>':
                scriptLines.set(i, "say('"+line.substring(1).trim()+"')");
                break;
            case '$':{
                List<String> matches = new ArrayList<String>();
                Matcher m = Pattern.compile("([\"'])(?:(?=(\\\\?))\\2.)*?\\1|[^\\s]+").matcher(line.substring(1));
                while (m.find() && matches.size()<4) {
                    matches.add(m.group());
                }
                if(matches.size()==0){
                    scriptLines.remove(i);
                    i--;
                    continue;
                }
                StringBuilder sb = new StringBuilder("sendMessage(");
                for(int u=0; u<matches.size(); u++) {
                    String arg = matches.get(u);
                    if(arg.charAt(0)!='"' && arg.charAt(0)!='\''){
                        if(u>0) sb.append(arg.replace("\"","\\\""));
                        else sb.append('"'+arg.replace("\"","\\\"")+'"');
                    }

                    else sb.append(arg);
                    sb.append(',');
                }
                sb.deleteCharAt(sb.length()-1);
                sb.append(')');
                scriptLines.set(i, sb.toString());
            } break;
        }
        scriptText.append(scriptLines.get(i));
        scriptText.append("\n");
    }
    Script script = groovyShell.parse(scriptText.toString());
    return (Scenario) script;
}
 
开发者ID:DeskChan,项目名称:DeskChan,代码行数:60,代码来源:ScenarioPlugin.java

示例4: generateCompilerConfigurationFromOptions

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
public static CompilerConfiguration generateCompilerConfigurationFromOptions(CommandLine cli) throws IOException {
    // Setup the configuration data
    CompilerConfiguration configuration = new CompilerConfiguration();

    if (cli.hasOption("classpath")) {
        configuration.setClasspath(cli.getOptionValue("classpath"));
    }

    if (cli.hasOption('d')) {
        configuration.setTargetDirectory(cli.getOptionValue('d'));
    }

    configuration.setParameters(cli.hasOption("pa"));

    if (cli.hasOption("encoding")) {
        configuration.setSourceEncoding(cli.getOptionValue("encoding"));
    }

    if (cli.hasOption("basescript")) {
        configuration.setScriptBaseClass(cli.getOptionValue("basescript"));
    }

    // joint compilation parameters
    if (cli.hasOption('j')) {
        Map<String, Object> compilerOptions = new HashMap<String, Object>();

        String[] namedValues = cli.getOptionValues("J");
        compilerOptions.put("namedValues", namedValues);

        String[] flags = cli.getOptionValues("F");
        if (flags != null && cli.hasOption("pa")){
            flags = Arrays.copyOf(flags, flags.length + 1);
            flags[flags.length - 1] = "parameters";
        }
        compilerOptions.put("flags", flags);

        configuration.setJointCompilationOptions(compilerOptions);
    }

    if (cli.hasOption("indy")) {
        configuration.getOptimizationOptions().put("int", false);
        configuration.getOptimizationOptions().put("indy", true);
    }

    String configScripts = System.getProperty("groovy.starter.configscripts", null);
    if (cli.hasOption("configscript") || (configScripts != null && !configScripts.isEmpty())) {
        List<String> scripts = new ArrayList<String>();
        if (cli.hasOption("configscript")) {
            scripts.add(cli.getOptionValue("configscript"));
        }
        if (configScripts != null) {
            scripts.addAll(StringGroovyMethods.tokenize((CharSequence) configScripts, ','));
        }
        processConfigScripts(scripts, configuration);
    }

    return configuration;
}
 
开发者ID:apache,项目名称:groovy,代码行数:59,代码来源:FileSystemCompiler.java


注:本文中的org.codehaus.groovy.control.CompilerConfiguration.setSourceEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。